1 / 16

DT228/3 Web Development

DT228/3 Web Development. JSP: Actions elements and JSTL. So far, have looked at these. Introduction. Previously, identified that JSP provides a variety of techniques to enable dynamic processing:. Directive elements. Scripting elements. Action elements and JSTL. Java Beans.

lavi
Download Presentation

DT228/3 Web Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. So far, have lookedat these 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 <%, they just use the < character (like HTML) <prefix:action_name>body </prefix:action_name >

  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 < and > • The tag names have an embedded colon character “:” in them, the part before the colon (prefix) describes the type of the tag <prefix:action_name> body </prefix:action_name> • 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. <img src = “..”) • Full syntax of JSP Action Elements is: • <prefix:action_name attr1 = “value” attr2 = “value2” action_body</prefix:action_name>If the element doesn’t have a body, can lose the end tag and use shorthand syntax of:<prefix:action_name attr1 = “value” attr2 = “value2” /> For example: <jsp:include page="scripts/login.jsp" />

  6. JSP Action elements Two types 1. 2. JSP Pre-defined tags External tag library (e.g. JSTL) Tags prefix is <jsp: ….> Tags prefix is whatever developer chooses or library recommends Customand 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:<jsp:forward> • <jsp:include> • <jsp:param> • <jsp:plugin> • <jsp:useBean> • <jsp:getProperty> • <jsp:setProperty> • 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 <jsp:include> • Standard Action Example: <JSP: include> tag • Example: • <HTML> <BODY> • Going to include hello.jsp...<BR> • <jsp:include page="hello.jsp"/> • </BODY> • </HTML> • Executes the included JSP page and adds its output into the this page

  10. JSP Predefined Tag Example <jsp:include> • What’s Difference from Using the ‘include’ directive?e.g. <%@ include file = ‘hello.jsp’ %> • 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 <jsp:forward> • Standard Action Example: <JSP: forward> tag • Stops processing of one page and starts processing the page specified by the page attribute • Example: • <HTML> <BODY> • Error occurred…please wait<BR> • <jsp:forward page=“errorpage.jsp"/> • </BODY> • </HTML>

  12. JSP Predefined Tag Example <jsp:param> • Standard Action Example: <JSP: param> tag • Can be used to pass parameters when using <jsp:include> <JSP:forward> or jsp:params block • Example • <jsp:include page="login.jsp"> • <jsp:param name="username" value="jsmith" /> • </jsp:include> 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 <jsp: > 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 <taglib>directive

  15. JSP Action elements: External tag libraries – custom Example of custom tag library supplied with Blazix web server Prefix to be used Library location <%@ taglib prefix="blx" uri="/blx.tld" %> <jsp:useBean id="user" class="UserData" scope="session"/> <HTML> <BODY> <blx:getProperty name="user" property="*"> <FORM METHOD=POST ACTION="SaveName.jsp"> Your name? <INPUT TYPE=TEXT NAME=username><BR> Your e-mail address? <INPUT TYPE=TEXT NAME=email><BR> Your age? <INPUT TYPE=TEXT NAME=age SIZE=4> <P><INPUT TYPE=SUBMIT> </FORM> </blx:getProperty> </BODY> </HTML> 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

More Related