Pre-assessment Questions

Slides:



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

CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Michael Brockway Application Integration JavaServer Pages l Introduction & Overview l Implicit Objects l Scripting l Standard Actions l Directives l References.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
DT228/3 Web Development JSP: Directives and Scripting elements.
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.
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.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
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.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
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.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
16-Oct-15 JSP Implicit Objects. 2 JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer.
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.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
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.
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.
Java Server Pages Introduction. Servlet Drawbacks Web page designer will need to know servlets to design the page. Servlet will have to be compiled for.
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.
Web Technologies Java Beans & JSP By Praveen Kumar G.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
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.
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.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
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.
Chapter 14 Using JavaBeans Components in JSP Documents.
JSP Elements Chapter 2.
Developing JavaServer Pages
Java Server Pages (JSP)
Java Server Pages.
Java Server Pages By: Tejashri Udavant..
Scripted Page Web App Development (Java Server Pages)
Pre assessment Questions
Pre-assessment Questions
Introduction to JSP Java Server Pages
Knowledge Byte In this section, you will learn about:
Pre-assessment Questions
JSP(Java Server Pages)
Invoking Java Code from JSP
Java Server Pages (JSP)
MSIS 655 Advanced Business Applications Programming
Introduction to Java Server Pages
Java Server Pages.
Java Server Pages B.Ramamurthy.
Objectives In this lesson you will learn about: Need for servlets
COP 4610L: Applications in the Enterprise Spring 2005
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:

Pre-assessment Questions Identify the correct statement. a) The Request Dispatcher object can only be used to include the output of another document. b) The Request Dispatcher object can only be used to forward the request to another document. c) The Request Dispatcher object can be used to forward the request to another document or include the output of another document. d) The Request Dispatcher object can neither be used to forward the request to another document nor can be used to include the output of another document. J2EE Web Components

Pre-assessment Questions (Contd.) 2. Identify the servlet attribute that is inherently thread safe. a) Local variables b) Class variables c) Context attributes d) Session attributes J2EE Web Components

Pre-assessment Questions (Contd.) 3. Which method is not included in the life cycle method of a Servlet filter? a) init() b) start() c) doFilter() d) destroy() 4. Identify the false statement. a) A servlet filter is an object that intercepts the requests and responses that flow between a client and a servlet. b) A servlet filter can modify the headers and contents of a request coming from a Web client and forward it to the target servlet. c) A servlet filter can also intercept and manipulate the headers and contents of the response that the servlet sends back. d) A servlet filter can process multiple client requests using a single servlet filter instance. J2EE Web Components

Pre-assessment Questions (Contd.) 5. Consider the following statements: Statement A: The include() method of RequestDespatcher class is used to include the output of another document. Statement B: The forward() method of RequestDespatcher class is used to forward the output to another document. Identify the correct option. a) Both, statements A and B are true b) Statement A is true and B is false c) Statement A is false and B is true d) Both, statements A and B are false J2EE Web Components

Solutions to Pre-assessment Questions 1. c. The Request Dispatcher object can be used to forward the request to another document or include the output of another document. 2. a. local variables 3. b. start() 4. d. A servlet filter can process multiple client requests using a single servlet filter instance. 5. b. A is true and B is false J2EE Web Components

Objectives In this lesson, you will learn about: Need for JSP Life cycle of JSP application Components of JSP Classes in JSP API Steps to create and deploy a JSP application J2EE Web Components

JSP Technology Introduction to JSP Technology JSP technology facilitates the segregation of the work profiles of a Web designer and a Web developer. A Web designer can design and formulate the layout for a Web page by using HTML. A Web developer, working independently, can use Java code and other JSP specific tags to code the business logic. J2EE Web Components

JSP Technology (Contd.) Differences between servlets and JSP are: Servlets tie up files to independently handle the static presentation logic and the dynamic business logic. On the other hand, JSP allows Java to be embedded directly into an HTML page by using special tags. Servlet programming involves extensive coding. Any changes made to the code requires identification of the static code content and dynamic code content to facilitate incorporation of the changes. On the other hand, a JSP page, by virtue of the separate placement of the static and dynamic content, facilitates both Web developers and the Web designer to work independently. J2EE Web Components

JSP Technology (Contd.) JSP Life Cycle is represented as shown: J2EE Web Components

JSP Technology (Contd.) JSP life cycle methods are: jspInit(): Is invoked at the time when the servlet is initialized. jspService(): Is invoked when request for the JSP page is received. jspDestroy(): Is invoked before the servlet is removed from the service. J2EE Web Components

JSP Technology (Contd.) The following code shows the sample structure of a JSP Page: <%--This is the HTML content--%> <%@ page language=”java” %> <HTML> <HEAD><TITLE>Simple JSP example></TITLE></HEAD> <BODY> <H1>This is a code within the JSP tags to display the server time</H1> <%--This is the JSP content that displays the server time by using the Date class of the java.util package--%> <% java.util.Date now=new java.util.Date(); %> <H2><%= now.getHours() %>:<% =now.getMinutes() %>:<% =now.getSeconds() %></H2> </BODY> </HTML> J2EE Web Components

Components of a JSP Page The three components of a JSP page are: JSP directives JSP scripting JSP actions J2EE Web Components

Components of a JSP Page (Contd.) A directive element in a JSP page provides global information about a particular JSP page and is of three types: page Directive taglib Directive include Directive The syntax for defining a directive is: <%@ directive attribute=”value” %> J2EE Web Components

Components of a JSP Page (Contd.) The page Directive Defines attributes that notify the Web container about the general settings of a JSP page. The syntax of the page directive is: <%@ page attribute_list %> J2EE Web Components

Components of a JSP Page (Contd.) The following table describes the attributes supported by the page directive: Attribute Name Description language Defines the scripting language of the JSP page. extends Defines the extended parent class of the JSP generated servlet. import Imports the list of packages, classes, or interfaces into the generated servlet. session Specifies if the generated servlet can access the session or not. An implicit object, session, is generated if the value is set to true. The default value of session attribute is true. J2EE Web Components

Components of a JSP Page (Contd.) Attributes supported by the page directive are (Contd.): Attribute Name Description buffer Specifies the size of the out buffer. If size is set to none, no buffering is performed. The default value of buffer size is 8 KB. autoFlush Specifies that the out buffer be flushed automatically if the value is set to true. If the value is set to false, an exception is raised when the buffer is full. The default value of autoFlush attribute is true. isThreadSafe Specifies whether a JSP page is thread safe or not. J2EE Web Components

Components of a JSP Page (Contd.) Attributes supported by the page directive are (Contd.): Attribute Name Description errorPage Specifies that any un-handled exception generated will be directed to the URL. isErrorPage Specifies that the current JSP page is an error page, if the attribute value is set to true. The default value of isErrorPage attribute is false. contentType Defines the Multipurpose Internal Mail Extension (MIME) type for a response. The default value of the contentType attribute is text/html.   J2EE Web Components

Components of a JSP Page (Contd.) The include Directive Specifies the names of the files to be inserted during the compilation of the JSP page. Creates the contents of the included files as part of the JSP page. Inserts a part of the code that is common to multiple pages. The syntax of the include directive is: <%@ include file = ”URLname” %> J2EE Web Components

Components of a JSP Page (Contd.) The taglib Directive Imports a custom tag into the current JSP page. Associates itself with a URI to uniquely identify a custom tag. Associates a tag prefix string that distinguishes a custom tag with the other tag library used in a JSP page. The syntax to import a taglib directive in the JSP page is: <%@ taglib uri=“tag_lib_URI” prefix=”prefix” %> J2EE Web Components

Components of a JSP Page (Contd.) The following table describes the attributes of the taglib directive: Attribute Description uri Locates the TLD file of a custom tag. prefix Defines a prefix string to be used for distinguishing a custom tag instance.   J2EE Web Components

Components of a JSP Page (Contd.) JSP Scripting Elements Embed Java code directly into an HTML page. Include various scripting elements, which are: Declarations: Provide a mechanism to define variables and methods. Declarative statements are placed within <%! and %> symbols and always end with a semicolon. Expressions: Insert values directly into the output. The syntax to include a JSP expressions in the JSP file is: <%= expression%> Scriptlets: Consists of valid Java code snippets that are enclosed within <% and %> symbols. The syntax to declare JSP scriptlets to include valid Java code is: <% Java code %> J2EE Web Components

Components of a JSP Page (Contd.) JSP Implicit Objects are: Pre-defined variables that can be included in JSP expressions and scriptlets. Implemented from servlet classes and interfaces. J2EE Web Components

Components of a JSP Page (Contd.) The following table describes various JSP implicit objects: Implicit Object Class Description application javax.servlet.ServletContext The application object defines a Web application. Usually, it is the application in the current Web context. config javax.Servlet.ServletConfig Represents the object of a ServletConfig class. exception java.lang.Throwable Represents the Throwable exception, in a JSP page.     J2EE Web Components

Components of a JSP Page (Contd.) Various JSP implicit objects are (Contd.): Implicit Object Class Description out javax.servlet.jsp.JspWriter Represents an object of JspWriter to send response to the client. JspWriter extends the PrintWriter class and is used by JSP pages to send client responses. page java.lang.Object Represents the current instance of the JSP page that in turn is used to refer to the current instance of the generated servlet. session javax.servlet.http.HttpSession Represents a session object of HttpSession interface. J2EE Web Components

Components of a JSP Page (Contd.) Various JSP implicit objects are (Contd.): Implicit Object Class Description response javax.servlet.http.HttpServletResponse Represents a response object of HttpServletResponse that is used to send an HTML output to the client. request javax.servlet.http.HttpServletRequest Represents a request object of HttpServletRequest. It is used to retrieve data submitted along with a request. pageContext javax.servlet.jsp.PageContext Represents a page context for a JSP page.   J2EE Web Components

Components of a JSP Page (Contd.) JSP Actions Perform tasks, such as insertion of files, reusing beans, forwarding a user to another page, and instantiating objects. The syntax to use a JSP action in a JSP page is: <jsp:attribute> J2EE Web Components

Description of Attributes Components of a JSP Page (Contd.) The following table describes various JSP action tags: JSP Action Description Attribute Description of Attributes <jsp:useBean> Invokes and searches for an existing bean. id   class scope beanName Uniquely identifies the instance of the bean. Identifies the class from which the bean objects are to be implemented. Defines the scope of the bean. Defines the referential name for the bean. J2EE Web Components

Description of Attributes Components of a JSP Page (Contd.) Various JSP action tags are (Contd.): JSP Action Description Attribute Description of Attributes <jsp:getProperty> Retrieves the property of a bean. name property Defines the name for the bean. Defines the property from which the values are to be retrieved. J2EE Web Components

Description of Attributes Components of a JSP Page (Contd.) Various JSP action tags are (Contd.): JSP Action Description Attribute Description of Attributes <jsp:setProperty> Used to set the property for a bean name   property value param Specifies a name for the bean. Defines the property for which values are to be set. Defines an explicit value for the bean property. Defines the name of the request parameter to be used. J2EE Web Components

Description of Attributes Components of a JSP Page (Contd.) Various JSP action tags are (Contd.): JSP Action Description Attribute Description of Attributes <jsp:forward> Used to forward a request to a target page. page Specifies the URL of the target page. <jsp:include> Includes a file in the current JSP page. flush Specifies the URL of the resource to be included. Specifies whether the buffer should be flushed or not. The flush value can be either true or false. J2EE Web Components

Description of Attributes Components of a JSP Page (Contd.) Various JSP action tags are (Contd.): JSP Action Description Attribute Description of Attributes <jsp:param> Defines a parameter to be passed to an included or forwarded page. name   value Defines the name of the reference parameter. Defines the value of the specified parameter. <jsp:plugin> Executes a Java applets or a JavaBean. type code codebase Defines the type of plug-in to be included. Defines the name of the class to be executed by the plug-in. Defines the path of the code. J2EE Web Components

Programming in JSP Classes of JSP API The ErrorData Class The JSPWriter Class The PageContext Class J2EE Web Components

Programming in JSP (Contd.) The ErrorData Class Defines error information for error pages. Sets the value of the page directive, isErrorPage to true, to indicate that a page is an error page. Contains various methods, which are: getRequestURL(): Returns the requested URL in the form of a string. setServletName(): Returns the name of the servlet invoked in the form of a string. getStatusCode(): Returns the status code of the error in the form of an integer. getThrowable(): Returns the Throwable exception that caused the error. J2EE Web Components

Programming in JSP (Contd.) The JspWriter Class Writes action and template data in a JSP page. Refers the object of JspWriter class by the implicit variable, out. Contains various methods, which are: clear() close() flush() getBufferSize() print() println() J2EE Web Components

Programming in JSP (Contd.) The PageContext Class Provides context information when JSP is used in the servlet environment Contains various methods, which are: forward() getPage() getRequest() getResponse() getServletConfig() getServletContext() getSession() include() J2EE Web Components

Programming in JSP (Contd.) Steps to Create a JSP Application Create a user interface using HTML: Accepts inputs from the user. The user inputs are passed as a request to the JSP page. Create a JSP page: Provides the business logic to process the request passed from the HTML interface. In addition, the JSP page sends the response back to the Web browser. Package the user interface and JSP page: Packs the HTML and JSP page using the deploytool utility to create a JSP application. Deploy the package you have created: Deploys the JSP application on the J2EE1.4 Application Server to access its services. Access the application using a Web browser: Accesses the JSP application using a Web browser. J2EE Web Components

Demonstration-Developing a JSP Application Problem Statement John Barrett, the Chief Technology Officer (CTO) has entrusted the development team with the task of creating an application that validates the customer id and password of every customer before they can access their account details. The customer id has to be in a numeric form. He also wants that an error message should be displayed to the customer, if the entered customer id or password is incorrect. Before the changes can be made to the entire application, John wants to test this functionality by making a sample application for a specific customer. Larry Williams, the programmer has been assigned the task of implementing this functionality. Larry decides to use JSP for developing this application and incase any error occurs, the details of the error should be displayed. J2EE Web Components

Demonstration-Developing a JSP Application (Contd.) Solution To solve the given problem, perform the following tasks: 1. Create a Login Page Using HTML. 2. Create an Authentication Page Using JSP. 3. Create an Error Page Using JSP. 4. Package the JSP Application. 5. Deploy the JSP Application. 6. Access the JSP Application. J2EE Web Components

Summary In this lesson, you learned: JSP technology has facilitated the segregation of the work profiles of a Web designer and a Web developer. A JSP page, after compilation, generates a servlet and therefore incorporates all servlet functionalities. The request-response cycle of JSP essentially comprises of two phases: Translation phase Request-processing phase A JSP page consists of regular HTML tags representing the static content and the code enclosed within special tags representing the dynamic content. Different elements that are used in JSP page are: JSP directives JSP actions JSP scripting J2EE Web Components

Summary (Contd.) Objects in JSP can be created either implicitly by using directives, explicitly by using standard actions, or directly by declaring them within scriptlets. JSP actions are used to perform tasks, such as insertion of files, reusing beans, forwarding a user to another page, and instantiating objects. JSP page uses various JSP API classes, such as ErrorData, JspWriter, and PageContext that are defined in the javax.servlet.jsp package. You need to follow the following steps to develop a JSP application: Create a user interface. Create a JSP page. Package the user interface and JSP page into a Web application. Deploy the Web application on the J2EE 1.4 Application Server. Access the Web application in the Web browser. JSP applications are developed using the JSP directives, JSP actions, and JSP scripting tags. J2EE Web Components