 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.

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)
Java Server Pages Jeffrey Jongko. Introduction Java Server Pages (JSP) technology was created by Sun Microsystems and is built on top of Sun’s Java Servlet.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 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.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
Chapter 25: JavaServer Pages Outline 25.1 Introduction 25.2 JavaServer Pages Overview 25.3 First JavaServer Page Example 25.4 Implicit Objects 25.5 Scripting.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Pertemuan 10 Pemrograman JSP Matakuliah: T0053/Web Programming Tahun: 2006 Versi: 2.
Java Server Pages B.Ramamurthy. Java Server Pages Servlets are pure Java programs. They introduce dynamism into web pages by using programmatic content.
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,
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems JavaServer Pages (JSP)
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.
JavaServer Pages TM Introduce by
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
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.
11. Java-Based Web: JSP, JSF. 2 Motto: Rule 1: Our client is always right Rule 2: If you think our client is wrong, see Rule 1. - Anonymous.
 2002 Prentice Hall. All rights reserved. JavaServer Pages.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 25: JavaServer Pages Outline 25.1 Introduction 25.2 JavaServer Pages Overview 25.3 First JavaServer.
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.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Introducing.
Introduction to Java Server Pages (JSPs) Robert Thornton.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 25: JavaServer Pages Outline 25.1 Introduction 25.2 JavaServer Pages Overview 25.3 First JavaServer.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
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.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.
Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.
intro JSP Pertemuan 8 Matakuliah: Web Programming Tahun: 2009.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
 2005 Pearson Education, Inc. All rights reserved JavaServer Pages (JSP)
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 25: JavaServer Pages Outline 25.1 Introduction 25.2 JavaServer Pages Overview 25.3 First JavaServer.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© 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.
 2002 Prentice Hall. All rights reserved. Chapter 10: JavaServer Pages Outline 10.1 Introduction 10.2 JavaServer Pages Overview 10.3 A First JavaServer.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
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.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
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 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.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
 2002 Prentice Hall. All rights reserved. Chapter 10: JavaServer Pages Outline 10.1 Introduction 10.2 JavaServer Pages Overview 10.3 A First JavaServer.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
Knowledge Byte In this section, you will learn about:
JavaServer Pages (JSP)
MSIS 655 Advanced Business Applications Programming
COP 4610L: Applications in the Enterprise Spring 2005
J2EE Lecture 1:Servlet and JSP
Presentation transcript:

 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer Pages Overview 37.3 First JavaServer Page Example 37.4 Implicit Objects 37.5 Scripting Scripting Components Scripting Example 37.6 Standard Actions Action Action Action 37.7 Directives page Directive include Directive 37.8 Case Study: Guest Book 37.9 Web Resources

 2004 Prentice Hall, Inc. All rights reserved. Objectives In this lesson, you will learn: –To be able to create and deploy JavaServer Pages. –To use JSP’s implicit objects and scriptlets to create dynamic Web pages. –To specify global JSP information with directives. –To use actions to manipulate JavaBeans in a JSP, to include resources dynamically and to forward requests to other JSPs.

 2004 Prentice Hall, Inc. All rights reserved Introduction JavaServer Pages –Extension of Servlet technology Web content delivery Reuse existing Java components –Without programming Java Create custom tags –Encapsulate complex functionality Classes and interfaces specific to JSP –Package javax.servlet.jsp –Package javax.servlet.jsp.tagext

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview Key components –Directives –Actions –Scriptlets –Tag libraries

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview (cont.) Directive –Message to JSP container i.e., program that compiles/executes JSPs –Enable programmers to specify Page settings Content to include from other resources Custom tag libraries used in the JSP

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview (cont.) Action –Predefined JSP tags that encapsulate functionality –Often performed based on information from client request –Can be used to create Java objects for use in scriptlets

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview (cont.) Scriptlet –Also called “Scripting Elements” –Enable programmers to insert Java code in JSPs –Performs request processing Interacts with page elements and other components to implement dynamic pages

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview (cont.) Custom Tag Library –JSP’s tag extension mechanism –Enables programmers to define new tags Tags encapsulate complex functionality –Tags can manipulate JSP content

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview (cont.) JSPs –Look like standard HTML or XHTML Normally include HTML or XHTML markup –Known as fixed-template data –Used when content is mostly fixed-template data Small amounts of content generated dynamically Servlets –Used when small amount of content is fixed-template data Most content generated dynamically

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview (cont.) Some servlets do not produce content –Invoke other servlets and JSPs JSPs execute as part of a Web server –JSP container JSP first request –JSP container translates a JSP into a servlet Handle the current and future requests Code that represents the JSP –Placed in servlet’s _jspService method

 2004 Prentice Hall, Inc. All rights reserved JavaServer Pages Overview (cont.) JSP errors –Translation-time errors Occur when JSPs are translated into servlets –Request-time errors Occur during request processing Methods jspInit and jspDestroy –Container invokes when initializing and terminating a JSP Methods are defined in JSP declarations –Part of the JSP scripting mechanism

 2004 Prentice Hall, Inc. All rights reserved A First JavaServer Page Example Simple JSP example (Fig. 37.1) –Demonstrates Fixed-template data (XHTML markup) Creating a Java object ( java.util.Date ) Automatic conversion of JSP expression to a String meta element to refresh Web page at specified interval –First invocation of clock.jsp Notice the delay while: –JSP container translates the JSP into a servlet –JSP container compiles the servlet –JSP container executes the servlet Subsequent invocations should not experience the same delay

 2004 Prentice Hall, Inc. All rights reserved. Outline Clock.jsp (1 of 2) meta element refreshes the Web page every 60 seconds

 2004 Prentice Hall, Inc. All rights reserved. Outline Clock.jsp (2 of 2) Creates Date object that is converted to a String implicitly and displayed in paragraph ( p ) element

 2004 Prentice Hall, Inc. All rights reserved. Outline Clock.jsp

 2004 Prentice Hall, Inc. All rights reserved Implicit Objects Implicit Objects –Provide access to many servlet capabilities within a JSP –Four scopes Application scope –Objects owned by the container application –Any servlet or JSP can manipulate these objects Page scope –Objects that exist only in page in which they are defined –Each page has its own instance of these objects Request scope –Objects exist for duration of client request –Objects go out of scope when response sent to client Session scope –Objects exist for duration of client’s browsing session –Objects go out of scope when client terminates session or when session timeout occurs

 2004 Prentice Hall, Inc. All rights reserved.

37.5 Scripting Scripting –Dynamically generated content –Insert Java code and logic in JSP using scripting

 2004 Prentice Hall, Inc. All rights reserved Scripting Components JSP scripting components –Scriptlets (delimited by ) –Comments JSP comments (delimited by ) XHTML comments (delimited by ) Java’s comments (delimited by // and /* and */ ) –Expressions (delimited by ) –Declarations (delimited by ) –Escape sequences

 2004 Prentice Hall, Inc. All rights reserved Scripting Components (cont.)

 2004 Prentice Hall, Inc. All rights reserved Scripting Example Demonstrate basic scripting capabilities –Responding to get requests

 2004 Prentice Hall, Inc. All rights reserved. Outline welcome.jsp (1 of 2) Scriptlets used to insert Java code Use request implicit object to get parameter

 2004 Prentice Hall, Inc. All rights reserved. Outline welcome.jsp (2 of 2) JSP expressionScriptlets used to insert Java code

 2004 Prentice Hall, Inc. All rights reserved. Outline welcome.jsp

 2004 Prentice Hall, Inc. All rights reserved Standard Actions JSP standard actions –Provide access to common tasks performed in a JSP Including content from other resources Forwarding requests to other resources Interacting with JavaBeans –JSP containers process actions at request time –Delimited by and

 2004 Prentice Hall, Inc. All rights reserved Standard Actions

 2004 Prentice Hall, Inc. All rights reserved Action action –Enables dynamic content to be included in a JSP –More flexible than include directive Requires more overhead when page contents change frequently

 2004 Prentice Hall, Inc. All rights reserved Action (cont.)

 2004 Prentice Hall, Inc. All rights reserved. Outline banner.html (1 of 1)

 2004 Prentice Hall, Inc. All rights reserved. Outline toc.html (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline toc.html (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline clock2.jsp (1 of 2) Use Locale to format Data with specified DataFormat

 2004 Prentice Hall, Inc. All rights reserved. Outline clock2.jsp (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline include.jsp (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline include.jsp (2 of 3) Use JSP action to include banner.html Use JSP action to include toc.html

 2004 Prentice Hall, Inc. All rights reserved. Outline include.jsp (3 of 3) Use JSP action to include clock2.jsp

 2004 Prentice Hall, Inc. All rights reserved. Outline

 2004 Prentice Hall, Inc. All rights reserved Action action –Enables JSP to forward request to different resources Can forwarded requests only resources in same context action –Specifies name/value pairs of information Name/Value pairs are passed to other actions

 2004 Prentice Hall, Inc. All rights reserved. Outline forward1.jsp (1 of 2) Forward request to forward2.jsp

 2004 Prentice Hall, Inc. All rights reserved. Outline forward1.jsp (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline forward2.jsp (1 of 2) Receive request from forward1.jsp, then get firstName parameter from request

 2004 Prentice Hall, Inc. All rights reserved. Outline forward2.jsp (2 of 2) Get data parameter from request

 2004 Prentice Hall, Inc. All rights reserved Action action –Enables JSP to manipulate Java object Creates Java object or locates an existing object for use in JSP

 2004 Prentice Hall, Inc. All rights reserved Action (cont.)

 2004 Prentice Hall, Inc. All rights reserved. Outline Rotator.java (1 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline Rotator.java (2 of 2) Update Rotator so subsequent calls to getImage and getLink return information for different advertisements Return image file name for book cover image Return hyperlink to book at Amazon.com

 2004 Prentice Hall, Inc. All rights reserved. Outline adrotator.jsp (1 of 2) Use jsp:useBean action to obtain reference to Rotator object Invoke Rotator ’s nextAd method

 2004 Prentice Hall, Inc. All rights reserved. Outline adrotator.jsp (2 of 2) Define hyperlink to Amazon.com site

 2004 Prentice Hall, Inc. All rights reserved Action (cont.)

 2004 Prentice Hall, Inc. All rights reserved Directives JSP directives –Messages to JSP container –Enable programmer to: Specify page settings Include content from other resources Specify custom-tag libraries –Delimited by

 2004 Prentice Hall, Inc. All rights reserved Directives (cont.)

 2004 Prentice Hall, Inc. All rights reserved page Directive JSP page directive –Specifies JSP’s global settings in JSP container

 2004 Prentice Hall, Inc. All rights reserved page Directive (cont.)

 2004 Prentice Hall, Inc. All rights reserved page Directive (cont.)

 2004 Prentice Hall, Inc. All rights reserved page Directive (cont.)

 2004 Prentice Hall, Inc. All rights reserved include Directive JSP include directive –Includes content of another resource at JSP translation time Not as flexible as action

 2004 Prentice Hall, Inc. All rights reserved. Outline includeDirective.jsp (1 of 3)

 2004 Prentice Hall, Inc. All rights reserved. Outline includeDirective.jsp (2 of 3) Use include directive to include banner.html Use include directive to include toc.html

 2004 Prentice Hall, Inc. All rights reserved. Outline includeDirective.jsp (3 of 3) Use include directive to include clock2.jsp

 2004 Prentice Hall, Inc. All rights reserved Case Study: Guest Book Demonstrate –Action –JSP page directive –JSP error pages –Use of JDBC

 2004 Prentice Hall, Inc. All rights reserved. Outline GuestBean.java (1 of 2) GuestBean defines three guest properties: firstName, lastName and

 2004 Prentice Hall, Inc. All rights reserved. Outline GuestBean.java (2 of 2)

 2004 Prentice Hall, Inc. All rights reserved. Outline GuestDataBean.java (1 of 3) GuestDataBean connects to guestbook database Load database driver

 2004 Prentice Hall, Inc. All rights reserved. Outline GuestDataBean.java (2 of 3) GuestDataBean provides methods getGuestList to manipulate database

 2004 Prentice Hall, Inc. All rights reserved. Outline GuestDataBean.java (3 of 3) GuestDataBean provides methods addGuest to manipulate database

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookLogin.jsp (1 of 5) page directive defines information that is globally available in JSP Use jsp:useBean actions to obtain references to GuestBean and GuestDataBean objects

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookLogin.jsp (2 of 5) Set properties of GuestBean with request parameter values

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookLogin.jsp (3 of 5)

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookLogin.jsp (4 of 5) Forward request to guestBookView.jsp

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookLogin.jsp (5 of 5)

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookView.jsp (1 of 4) Use page directive import to specify Java classes and packages that are used in JSP context Use jsp:useBean action to obtain reference to GuestDataBean

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookView.jsp (2 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookView.jsp (3 of 4) Scriptlet displays last name, first name and address for all guests

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookView.jsp (4 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookErrorView.jsp (1 of 3) Use page directive isErrorPage to specify that guestBookError- Page is an error page

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookErrorView.jsp (2 of 3) Use implicit object exception to determine error to be displayed

 2004 Prentice Hall, Inc. All rights reserved. Outline guestBookErrorView.jsp (3 of 3)

 2004 Prentice Hall, Inc. All rights reserved Case Study: Guest Book (Cont.)

 2004 Prentice Hall, Inc. All rights reserved Case Study: Guest Book (Cont.)

 2004 Prentice Hall, Inc. All rights reserved Case Study: Guest Book (Cont.)

 2004 Prentice Hall, Inc. All rights reserved Web Resources JSP at Sun Microsystems –java.sun.com/products/jsp Servlets at Sun Microsystems –java.sun.com/products/servlet J2EE at Sun Microsystems –java.sun.com/j2ee World Wide Web Consortium – Tutorials, tag libraries and software –jsptags.com Resources for JSP programmers –jspinsider.com