Presentation is loading. Please wait.

Presentation is loading. Please wait.

DT228/3 Web Development JSP: Actions elements and JSTL.

Similar presentations


Presentation on theme: "DT228/3 Web Development JSP: Actions elements and JSTL."— Presentation transcript:

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 Action elements and JSTL Scripting elements Java Beans So far, have looked at these

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 than scriplet programming Instead of <%, they just use the < character (like HTML) body

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 The tag names have an embedded colon character “:” in them, the part before the colon (prefix) describes the type of the tag body Note: Syntax of Action Elementags is based on XML Part after the “ :” is the Action Name

5 JSP Action elements Tags have associated attributes (like HTML e.g. <img src = “..”) Full syntax of JSP Action Elements is: If the element doesn’t have a body, can lose the end tag and use shorthand syntax of: For example:

6 JSP Action elements Two types Tags prefix is JSP Pre-defined tags Tags prefix is whatever developer chooses or library recommends External tag library (e.g. JSTL) (Also called Standard Action Elements) 1. 2. Custom and JSTL

7 JSP pre-defined tags (standard actions elements) External Tag library: -------  Custom -------  Java Standard tag library JSP Action elements

8 JSP Action elements: JSP Predefined Tags Also called JSP Standard Action Elements List of these elements are: See http://java.sun.com/products/jsp/syntax/1.1/syntaxref11.html for detailed attributes and values Used for Java Beans

9 JSP Predefined Tag Example Standard Action Example: tag Example: Going to include hello.jsp... Executes the included JSP page and adds its output into the this page

10 JSP Predefined Tag Example What’s Difference from Using the ‘include’ directive? e.g. 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 Standard Action Example: tag Stops processing of one page and starts processing the page specified by the page attribute Example: Error occurred…please wait

12 JSP Predefined Tag Example Standard Action Example: tag Can be used to pass parameters when using or jsp:params block Example Executes a login page jsp:param 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 tags Developers can develop their own Custom action elements using 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 directive

15 JSP Action elements: External tag libraries – custom Your name? Your e-mail address? Your age? Prefix to be used Library location Example of custom tag library supplied with Blazix web server 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


Download ppt "DT228/3 Web Development JSP: Actions elements and JSTL."

Similar presentations


Ads by Google