DT228/3 Web Development - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

DT228/3 Web Development

Description:

Can be used to pass parameters when using jsp:include JSP:forward or jsp:params block ... name='user' property='*' FORM METHOD=POST ACTION='SaveName.jsp' ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 17
Provided by: fsdf
Category:

less

Transcript and Presenter's Notes

Title: DT228/3 Web Development


1
DT228/3 Web Development
JSP Actions elements and JSTL
2
Introduction
  • Previously, identified that JSP provides a
    variety of techniques to enable dynamic
    processing
  • Directive elements
  • Scripting elements
  • Action elements and JSTL
  • Java Beans

3
JSP Action elements
  • Action elements are an important syntax element
    in JSP
  • They are represented by tags (as is HTML)
  • They assist JSP developers to develop in tags
    rather thanscriplet programming
  • Instead of lt, they just use the lt character
    (like HTML)

ltprefixaction_namegt body
lt/prefixaction_name gt
4
JSP Action elements
  • JSP tags have a start tag, a tag body and an
    end tag.
  • The start and end tag have the same name enclosed
    in lt and gt
  • The tag names have an embedded colon character
    in them, the part before the colon (prefix)
    describes the type of the tag

ltprefixaction_namegt body lt/prefixaction_na
megt
  • Part after the is the Action Name
  • Note Syntax of Action Elementags is based on XML

5
JSP Action elements
  • Tags have associated attributes (like HTML e.g.
    ltimg src ..)
  • Full syntax of JSP Action Elements is
  • ltprefixaction_name attr1 value attr2
    value2 action_bodylt/prefixaction_namegt
    If the element doesnt have a body, can lose the
    end tag and use shorthand syntax
    ofltprefixaction_name attr1 value attr2
    value2 /gt

For example
ltjspinclude page"scripts/login.jsp" /gt
6
JSP Action elements
Two types
1.
2.
JSP Pre-defined tags
External tag library (e.g. JSTL)
Tags prefix is ltjsp .gt
Tags prefix is whatever developer chooses or
library recommends
Custom and JSTL
(Also called Standard Action Elements)
7
JSP Action elements
JSP pre-defined tags (standard actions elements)
External Tag library -------? Custom
-------? Java Standard tag library
8
JSP Action elements JSP Predefined Tags
  • Also called JSP Standard Action Elements
  • List of these elements are ltjspforwardgt
  • ltjspincludegt
  • ltjspparamgt
  • ltjspplugingt
  • ltjspuseBeangt
  • ltjspgetPropertygt
  • ltjspsetPropertygt
  • See http//java.sun.com/products/jsp/syntax/1.1/sy
    ntaxref11.html for detailed attributes and values

Used for Java Beans
9
JSP Predefined Tag Example ltjspincludegt
  • Standard Action Example ltJSP includegt tag
  • Example
  • ltHTMLgt ltBODYgt
  • Going to include hello.jsp...ltBRgt
  • ltjspinclude page"hello.jsp"/gt
  • lt/BODYgt
  • lt/HTMLgt
  • Executes the included JSP page and adds its
    output into the this page

10
JSP Predefined Tag Example ltjspincludegt
  • Whats Difference from Using the include
    directive? e.g. lt_at_ include file hello.jsp
    gt
  • The include directive includes the contents of
    another file at compilation time. Good for
    including common static code e.g. header file,
    footer file. Good on performance ? included only
    once.
  • But, what if including dynamic common code (e.g.
    a navigation bar where links are read from the
    dB?).. need to re-run the file each time a
    request is made -? JSP include
  • JSP include incorporates the output of the
    included JSP file at run time

11
JSP Predefined Tag Example ltjspforwardgt
  • Standard Action Example ltJSP forwardgt tag
  • Stops processing of one page and starts
    processing the page specified by the page
    attribute
  • Example
  • ltHTMLgt ltBODYgt
  • Error occurredplease waitltBRgt
  • ltjspforward pageerrorpage.jsp"/gt
  • lt/BODYgt
  • lt/HTMLgt

12
JSP Predefined Tag Example ltjspparamgt
  • Standard Action Example ltJSP paramgt tag
  • Can be used to pass parameters when using
    ltjspincludegt ltJSPforwardgt or jspparams block
  • Example
  • ltjspinclude page"login.jsp"gt
  • ltjspparam name"username" value"jsmith" /gt
  • lt/jspincludegt

Executes a login page jspparam passes in
username to the login page
13
JSP Action Elements
JSP pre-defined tags (standard actions elements)
Done
External Tag library -------? Custom
-------? Java Standard tag library
14
JSP Action elements External tag libraries
custom
  • JSP 1.1. introduced tag libraries, allowing
    addition of tags beyond standard action ltjsp gt
    tags
  • Developers can develop their own Custom action
    elementsusing custom tag libraries
  • Custom tag libraries are useful where developers
    are working in teams reusabletags can be
    supplied to team via custom tag libraries.
  • The library is identified in the JSP page using
    the lttaglibgtdirective

15
JSP Action elements External tag libraries
custom
Example of custom tag library supplied with
Blazix web server
Prefix to be used Library location
lt_at_ taglib prefix"blx" uri"/blx.tld"
gt ltjspuseBean id"user" class"UserData"
scope"session"/gt ltHTMLgt ltBODYgt
ltblxgetProperty name"user" property""gt
ltFORM METHODPOST ACTION"SaveName.jsp"gt
Your name? ltINPUT TYPETEXT NAMEusernamegtltBRgt
Your e-mail address? ltINPUT TYPETEXT
NAMEemailgtltBRgt Your age? ltINPUT TYPETEXT
NAMEage SIZE4gt ltPgtltINPUT
TYPESUBMITgt lt/FORMgt lt/blxgetPropertygt
lt/BODYgt lt/HTMLgt
Tag from tag library
16
JSP Action Elements
JSP pre-defined tags (standard actions elements)
Done
External Tag library -------? Custom
Done -------? Java Standard tag library
Write a Comment
User Comments (0)
About PowerShow.com