Chapter 7: JSP Directives - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Chapter 7: JSP Directives

Description:

XML-compatible syntax (without using special characters): jsp:directive.taglib ... / 4 ... In web.xml: jsp-property-group url-pattern /example2/index2.jsp ... – PowerPoint PPT presentation

Number of Views:855
Avg rating:3.0/5.0
Slides: 12
Provided by: conest
Category:

less

Transcript and Presenter's Notes

Title: Chapter 7: JSP Directives


1
Chapter 7 JSP Directives
Reference Beginning JSP
2
Objectives
  • Processing of JSP Directives
  • JSP Directives
  • Page Directive
  • Taglib Directive
  • Include Directive

3
Review JSP Directives
  • Reference page 32
  • Directives
  • Gives special instructions to the JSP container
  • Not used to generate output directly
  • Allowable directives (more details in Chapter 7)
  • page directive
  • taglib directive
  • include directive
  • Syntax lt_at_ directive gt
  • XML-compatible syntax (without using special
    characters)
  • ltjspdirective.taglib /gt

4
Processing of JSP Directives
  • Reference Page 215
  • Phase 1 Translation
  • JSP page converted to Java code
  • Phase 2 Compilation
  • Java code is compiled into executable byte code.
  • The binary byte code is executed when an incoming
    HTTP request arrives at the server

5
Page Directive (1)
  • Reference page 217
  • language attribute
  • lt_at_ page language"java" gt
  • import attribute
  • lt_at_ page language"java" import
    "com.wrox.begjsp.ch03.,java.util. gt
  • contentType attribute
  • lt_at_ page language"java" contentType"text/html"
    gt
  • errorPage, isErrorPage attribute
  • Under ltTomcatgt\webapps\jsp-examples\error
  • err.jsp lt_at_ page errorPage"errorpge.jsp" gt
  • errorpge.jsp lt_at_ page isErrorPage"true" gt

6
Page Directive (2)
  • Other attributes
  • session (default true), isELIgnored (default
    false)
  • info (for JSP dev tools), extends (not
    recommended)
  • XML syntax example
  • Example 1 xindex.jsp
  • ltjsproot
  • xmlnsjsp"http//java.sun.com/JSP/Page"
  • version"2.0"gt
  • ltjspdirective.page language"java"
    contentType"text/html" /gt
  • lthtmlgtlt/htmlgt
  • lt/jsprootgt

7
Page Directive Example
  • index2.jsp contentType"text/xml
  • Result
  • JSP container responds with an XML document

8
Taglib Directive
  • Reference page 223
  • uri attribute
  • To locate TLD file that describes the tag library
  • lt_at_ taglib prefix"c" uri"http//java.sun.com/jsp
    /jstl/core" gt
  • tagdir attribute
  • To locate tag files for a tag library
  • lt_at_ taglib prefix"wt" tagdir"/WEB-INF/tags/wroxt
    ags" gt
  • prefix attribute
  • Prefix to be used in the JSP page for referring
    to this tag library
  • ltcwhen test"param.pg 'mine'"gtltwtmyPage/gtlt
    /cwhengt

9
No Taglib Directive Example
  • Using JSP Tags
  • without taglib directive
  • E.g., index2.jsp
  • In web.xml
  • ltjsp-property-groupgt
  • lturl-patterngt/example2/index2.jsplt/url-patterngt
  • ltinclude-preludegt/WEB-INF/jspf/pre1.jspflt/include
    -preludegt
  • lt/jsp-property-groupgt
  • In pre1.jsp
  • lt_at_ taglib prefix"c" uri"http//java.sun.com/jsp
    /jstl/core" gt
  • lt_at_ taglib prefix"wt" tagdir"/WEB-INF/tags/wroxt
    ags" gt

10
Include Directive
  • Reference page 231
  • file attribute
  • Mandatory
  • Merge content of external files with current JSP
    during translation phase
  • lt_at_ include file"news.jsp" gt
  • Include directive vs. ltjspincludegt
  • Translation time vs. request time
  • ltjspincludegt is recommended to overcome
    limitations (e.g., changes to JSP page is
    automatically recompiled)

11
Next Steps
  • Try It Out sections of Textbook (Chapter 7)
  • Examples 1, 2, 3
Write a Comment
User Comments (0)
About PowerShow.com