Web Technologies Java Beans & JSP By Praveen Kumar G.

Slides:



Advertisements
Similar presentations
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Advertisements

JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
© Copyright 2008 STI - INNSBRUCK Web Engineering Web Technologies II Lecture X – 9 th December 2008 Federico M. Facca.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
JSP – Java Server Pages Part 1 Representation and Management of Data on the Internet.
DT228/3 Web Development JSP: Directives and Scripting elements.
Including Files & Applets in JSP Documents Parts of this presentation provided by: Vijayan Sugumaran Decision and Information Sciences.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
1 CS6320 – JSP L. Grewe 2 Java Server Pages Servlets require you to write out entire page delivered with print statements Servlets require you to write.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
Slides © Marty Hall, book © Sun Microsystems Press 1 Including Files & Applets in JSP Documents Core Servlets & JSP book:
1 JSP – Java Server Pages Representation and Management of Data on the Internet.
What Are Beans? beans are simply Java classes that are written in a standard format. A bean class must have a zero-argument (default) constructor. A bean.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Jordan Anastasiade. All rights reserved.
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
Chapter 10 Overview of JSP Technology. Understanding the need for JSP JSP technology enables to mix regular, static HTML with dynamically generated content.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Slides © Marty Hall, book © Sun Microsystems Press 1 JSP Scripting Elements Core Servlets & JSP book:
SE-2840 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaServer Page.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
1 JSP – Java Server Page DBI – Representation and Management of Data on the Internet.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages (JSP)
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
CS-4220 Dr. Mark L. Hornick 1 Java Server Pages. HTML/JSPs are intended to be used as the views in an MVC- based web application Model – represents an.
Chapter 11 Invoking Java Code with JSP Scripting Elements.
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
JSP. Types of JSP Scripting Elements Expressions of the form, which are evaluated and inserted into the servlet's output. Scriptlets of the form, which.
Slides © Marty Hall, book © Sun Microsystems Press 1 Using JavaBeans with JSP Core Servlets & JSP book:
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
JSP – Java Server Page DBI – Representation and Management of Data on the Internet.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
1 Chapter 27 JavaServer Page. 2 Objectives F To know what is a JSP page is processed (§27.2). F To comprehend how a JSP page is processed (§27.3). F To.
INVOKING JAVA CODE WITH JSP SCRIPTING ELEMENTS. Creating Template Text A large percentage of your JSP document consists of static text (usually HTML),
JSP JavaServer Pages. What is JSP? Java based technology that simplifies the development of dynamic web sites JSP pages are HTML pages with embedded code.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
JSP in Action. JSP Standard Actions forward, include, useBean, setProperty, getProperty, text, element, and plugin Additional actions param, params,
Chapter 14 Using JavaBeans Components in JSP Documents.
JSP Directive and Objects. JSP Directives As discussed before There are 3 types of elements in JSP Directive Elements Scripting Elements Standard Action.
JSP Java Server Pages. Hello, !
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Developing JavaServer Pages
Java Server Pages By: Tejashri Udavant..
Scripted Page Web App Development (Java Server Pages)
Including Files and Applets in JSP Pages
Pre-assessment Questions
Invoking Java Code from JSP
Java Server Pages (JSP)
Java Server Pages JSP 11/11/2018.
JSP implicit objects & directive elements
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction.
Scripted Page Web Application Development (Java Server Pages)
Web Technologies Java Beans & JSP
Presentation transcript:

Web Technologies Java Beans & JSP By Praveen Kumar G

December 21, 2015© 2006 IIITM-K2 Java Beans What Are Beans? Beans are standard java objects. Must have a zero-arguments constructor. Should have no public fields. Values should be accessed through method calls, getXxx, setXxx & isXxx.

December 21, 2015© 2006 IIITM-K3 Java Bean (example) public class Person { private intage; private Stringname; … … … public void setAge(int age){ this.age = age; } public void setName(String name){ this.name = name; } public int getAge(){ return this.age; } public String getName(){ return this.name; } … … … }

December 21, 2015© 2006 IIITM-K4 Java Server Pages Overview of JSP Technology JSP Scripting Elements JSP Page Directives

December 21, 2015© 2006 IIITM-K5 Overview of JSP Technology What is JSP The need for JSP The benefits of JSP Advantages over other technologies Location of JSP pages

December 21, 2015© 2006 IIITM-K6 What is JSP Servlets – HTML in java code JSP – java code in HTML Java Server Pages JSP

December 21, 2015© 2006 IIITM-K7 JSP Lifecycle JSP to Servlet Translation JSP to Servlet Translation Servlet Compiled Servlet Compiled Servlet Loaded Servlet Loaded jspInit() called jspInit() called _jspService() called _jspService() called

December 21, 2015© 2006 IIITM-K8 The need for JSP With servlets It is hard to write and maintain HTML Cannot use standard HTML tools HTML is inaccessible to non-java developers

December 21, 2015© 2006 IIITM-K9 The benefits of JSP Easier to write and maintain HTML Can use standard HTML tools Can divide up development team

December 21, 2015© 2006 IIITM-K10 Advantages The Java advantage Extensive API Easy to learn Big development community Standardization & server support

December 21, 2015© 2006 IIITM-K11 Location of JSP pages Unlike servlets, JSP pages can be located in any of the locations where HTML files can be put.

December 21, 2015© 2006 IIITM-K12 JSP Scripting Elements JSP scripting elements enable us to insert java code into JSP files. There are three types – Expressions Scriptlets Declarations

December 21, 2015© 2006 IIITM-K13 JSP Expressions A JSP expression is used to insert java code directly into the output. Have the following form Eg: Current Time: Op: Current Time: Tue Aug 22 21:05:47 IST 2006 The expression is evaluated, converted to string and inserted into the page.

December 21, 2015© 2006 IIITM-K14 Predefined Variables To simplify expressions, JSP provides a number of predefined variables (implicit objects). request – the HttpServletRequest response – the HttpServletResponse session – the HttpSession out – the Writer (buffered version of type JspWriter) application – the ServletContext config – the ServletConfig pageContext – introduced to give single point of access to page attributes page – synonym for “this”

December 21, 2015© 2006 IIITM-K15 JSP Scriptlets To something more than just output the value of a simple expression. Allows the programmer to insert arbitrary code into the servlets _jspService method. Have the following form: Eg: <% String str = request.getParameter(“name”); out.print(“Name : ”+str); %>

December 21, 2015© 2006 IIITM-K16 JSP Declarations JSP declarations lets the programmer define methods or fields that get inserted into the main body of the generated servlet (outside the _jspService() method) Have the following form: Eg: <%! private String getMessage(){ return “This is a simple message!!”; } %>

December 21, 2015© 2006 IIITM-K17 XML Syntax XML like syntax for JSP expression, scriptlet & declaration … Supported by JSP versio 1.2 & above These are case sensitive, should be in lowercase

December 21, 2015© 2006 IIITM-K18 JSP Directives A JSP directive affects the overall structure of the servlet that results from the JSP page. A JSP directive has the form: There are three types: page, include & taglib

December 21, 2015© 2006 IIITM-K19 JSP Page Directive The page directive controls the structure of the servlet by importing classes, customizing the superclass, changing content type, etc. The JSP Page directive has the following attributes: import, contentType, pageEncoding, session,isELIgnored, buffer, autoFlush, info, errorPage, isThreadSafe, language & extends

December 21, 2015© 2006 IIITM-K20 JSP Page Directive Attributes import=“java.util.*, java.sql.*” contentType=“ text/html; charset=ISO ” pageEncoding=“Shift_JIS” session=“true/false” isELIgnored=“false/true” buffer=“size in kb” autoFlush=“true/false” info=“Some info message.” errorPage=“error.jsp” isErrorPage=“false/true” isThreadSafe=“true/false” language=“java” extends=“package.class” org.apache.jasper.runtime.HttpJspBase javax.servlet.jsp.HttpJspPage org.apache.jasper.runtime.HttpJspBase javax.servlet.jsp.HttpJspPage

December 21, 2015© 2006 IIITM-K21 Including Files There are three ways of including external files into a JSP document. … …

December 21, 2015© 2006 IIITM-K22 The jsp:include Action This includes the output of a secondary page at the time the main page is requested. The output of the sub page must be HTML generated by a servlet or JSP.

December 21, 2015© 2006 IIITM-K23 The Include Directive This includes directive is used to include a file in the main JSP at the time of translation into a servlet. The code of the included file is added to that of the JSP document.

December 21, 2015© 2006 IIITM-K24 Forwarding Requests This action is used to get the output of a JSP file completely from another JSP or servlet. The output of the auxiliary JSP or servlet is sent to the client, not that of the current JSP.

December 21, 2015© 2006 IIITM-K25 The jsp:plugin Action Used to embed a java applet into the generated output. Java applets are rarely used in web pages now a days. <jsp:plugin type=“applet” code=“MyApplet.class” width=“400” height=“300”>

December 21, 2015© 2006 IIITM-K26 jsp:plugin Attributes type=“applet” bean can also be used. Code=“MyApplet.class” width=“…” height=“…” codebase=“base directory for the applet” align=“…” laet, right, top, bottom or middle hspace=“…” vspace=“…” archive=“specify JAR file” title=“Title for the Applet” jreversion=“1.2” iepluginurl=“…” nspluginurl=“…”

December 21, 2015© 2006 IIITM-K27 jsp:plugin Parameters & Fallback <jsp:plugin type=“applet” code=“MyApplet.class” width=“400” height=“300”> Java Plugin needed.

December 21, 2015© 2006 IIITM-K28 Using Java Beans & JSP There are three main constructs to use Java Beans in JSP.

December 21, 2015© 2006 IIITM-K29 jsp:useBean Used to load a bean to be used in the JSP document. Syntax: Eg: Equivalent to:

December 21, 2015© 2006 IIITM-K30 Getting bean properties Used to read properties from beans. Syntax: Eg: Equivalent to:

December 21, 2015© 2006 IIITM-K31 Setting bean properties Used to set properties of beans. Syntax: Eg: Equivalent to:

December 21, 2015© 2006 IIITM-K32 Properties & Request Parameters The value of a bean property can be set directly from the value of the corresponding request parameter. Syntax: Eg:

December 21, 2015© 2006 IIITM-K33 Sharing Beans (scope) The scope of a bean defines where the bean is stored and how it is accessible. By default it is accessible as a local variable. Other places of storing beans are the request, session and application. Syntax: Scopes: page, request, session & application

December 21, 2015© 2006 IIITM-K34 Page Scope The default scope of a bean. Bean is bound to a local variable in the _jspService method and also placed in the pageContext predefined variable, accessible by calling getAttribute() method. Syntax:

December 21, 2015© 2006 IIITM-K35 Request Scope In addition to being bound to a local variable, the bean is also placed in the HttpServletRequest object (request) for the duration of the current request. Accessible by getAttribute() method. Syntax:

December 21, 2015© 2006 IIITM-K36 Session Scope In addition to being bound to a local variable, the bean is also placed in the HttpSession object (session). Accessible by getAttribute() method. Syntax:

December 21, 2015© 2006 IIITM-K37 Application Scope In addition to being bound to a local variable, the bean is also placed in the ServletContext object (application). The servlet context is shared by all the JSP and servlets in the webapplication. Accessible by getAttribute() method. Syntax:

Questions ?