Click here to load reader

Module 5 Developing with JavaServer Pages Technology · PDF file 2 Developing with JSP Technology 5 Developing Applications for Java EE Platform 127 Ω Omega Ω JSP pages are text-based

  • View
    5

  • Download
    0

Embed Size (px)

Text of Module 5 Developing with JavaServer Pages Technology · PDF file 2 Developing with JSP...

  • 1

    Module 5 Developing with JavaServer Pages Technology

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    126 Ω Omega ΩDeveloping Applications for Java EE Platform

    ► Evaluate the role of JSP technology as a presentation Mechanism ► Author JSP pages ► Process data received from servlets in a JSP page ► Describe the use of tag libraries

    Objectives

  • 2

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    127 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP pages are text-based documents that describe how to process a request and create a response. ► Using JSP technology, a page designer creates a document to generate dynamic content. ► JSP elements:

    • Enable external object access • Add canned programming capabilities

    ► Source files for JSP pages typically end with the .jsp extension.

    JSP Technology as a Presentation

    Mechanism

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    128 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP technology: ► Uses beans to interact with server-side objects ► Uses tag libraries to develop and extend the canned capabilities provided by actions ► Allows for a high degree of separation between the static and dynamic content in a JSP page ► Provides (where necessary) a powerful scripting language for JSP pages ► Is an integral part of the Java EE platform, and so provides front-end access to EJB components

    JSP Technology as a Presentation

    Mechanism

  • 3

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    129 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP pages are web components that are based on the servlet model and that run as servlets:

    Presentation Using JSP Pages Compared

    to Servlets

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    130 Ω Omega ΩDeveloping Applications for Java EE Platform

    Presentation Using JSP Pages Compared

    to Servlets

  • 4

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    131 Ω Omega ΩDeveloping Applications for Java EE Platform

    You can separate programmatic functionality from presentation in JSP components in two ways: ► Incorporate classes with the tag and the JSTL:

    • Useful for carrying data into the JSP component • JSTL allows programmatic behavior without scriptlets

    ► Make use of custom tag libraries: • Most valuable when tag libraries are general-purpose

    and reusable • Less useful for page specific logic, such as unique form

    processing

    Worker Beans, JSTL, and Custom Tags

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    132 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP pages: ► Are translated into servlets on demand ► Can be deployed in the same manner as an HTML page, by copying the file onto the server

    JSP Page Deployment Mechanism

  • 5

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    133 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP Page Translation Procedure

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    134 Ω Omega ΩDeveloping Applications for Java EE Platform

    ► Ideally, a JSP page should be concerned with presentation logic only. A servlet is a better alternative for processing logic and for flow control. Using scripting code for processing logic and flow control within a JSP page results in problems that include: ► A JSP page author:

    • Must code well in the scripting language • Might need more business domain knowledge

    ► It is more difficult to see presentation information when you view the JSP page. ► Debugging is more difficult because of the added complexity and decreased clarity.

    Java Code Embedded in JSP Pages

  • 6

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    135 Ω Omega ΩDeveloping Applications for Java EE Platform

    A JSP page contains: ► Standard markup tags, such as HTML or XML ► Associated text data ► A variety of elements that are defined by the JSP specification

    Authoring JSP Pages

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    136 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP Page Components

  • 7

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    137 Ω Omega ΩDeveloping Applications for Java EE Platform

    Syntactic forms of tags based on JSP tags can be represented in two different ways:

    Syntactic Forms of JSP Tags

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    138 Ω Omega ΩDeveloping Applications for Java EE Platform

    ► Contain information to help a JSP container configure and run a JSP page ► Are associated with the compiled servlet that is created from the JSP page ► Do not produce output ► Have the following generic syntax:

    JSP Technology Directives

  • 8

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    139 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP Directives

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    140 Ω Omega ΩDeveloping Applications for Java EE Platform

    The page directive defines page-dependent attributes: ► An attribute and value pair cannot be redefined within a translation unit, with the exception of the include page directive. ► Redefining a page directive results in a fatal translation error, unless the new and the old definitions are the same.

    The page Directive

  • 9

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    141 Ω Omega ΩDeveloping Applications for Java EE Platform

    Examples using both styles of syntax:

    The page Directive D

    ev el

    op in

    g w

    ith J

    S P

    T ec

    hn ol

    og y5

    142 Ω Omega ΩDeveloping Applications for Java EE Platform

    JSP page Directives

  • 10

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    143 Ω Omega ΩDeveloping Applications for Java EE Platform

    The include Directive

    The include directive: ► Inserts the text of the specified resource into the .jsp file at page translation time ► Treats resources as static objects ► Can be other HTML files or other JSP pages that contain text, or code, or both

    Examples of the include directive:

    Or

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    144 Ω Omega ΩDeveloping Applications for Java EE Platform

    The include Directive

  • 11

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    145 Ω Omega ΩDeveloping Applications for Java EE Platform

    Declarations, Expressions, and Scriptlets

    Scripting elements allow a page designer to provide advanced programming capabilities. Scripting elements include: ► Declarations ► Expressions ► Scriptlets

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    146 Ω Omega ΩDeveloping Applications for Java EE Platform

    Declarations, Expressions, and Scriptlets

  • 12

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    147 Ω Omega ΩDeveloping Applications for Java EE Platform

    Declaration Scripting Elements

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    148 Ω Omega ΩDeveloping Applications for Java EE Platform

    Expression Scripting Elements

  • 13

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    149 Ω Omega ΩDeveloping Applications for Java EE Platform

    Scriptlet Scripting Elements

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    150 Ω Omega ΩDeveloping Applications for Java EE Platform

    Scriptlet Scripting Elements

  • 14

    D ev

    el op

    in g

    w ith

    J S

    P T

    ec hn

    ol og

    y5

    151 Ω Omega ΩDeveloping Applications for Java EE Platform

Search related