Servlet and Jsp Technology -Part4

Post on 10-Mar-2016

226 views 3 download

Tags:

description

Servlet and Jsp Technology -Part4

transcript

1

2

3

4

The isThreadSafe attribute is same as that of Servlet implementing SingleThreadModel.

For description about other attributes refer :http://java.sun.com/products/jsp/tags/11/syntaxref11.fm7.html. And http://www.servletworld.com/jsp-tutorials/jsp-page-directive.html

5

Include directive has access to all files within the application, even those file which are under WEB-INF folder and publically unavailable, so you can use include directive to include those files also which are under WEB-INF.

Use include directive to create a template using include directive which includes the header.jsp and footer.jsp to provide the consistent page layout throughout the application.

6

7

Custom tags follow XML syntax rules and can be defined to have attributes and body.

Custom tags are particularly useful in team environments where web designers perform JSP formatting and layout,

and web developers do the Java coding for applications and tag libraries.

Web designers do not need to learn Java, instead they can use familiar XML syntax to take advantage of custom tag libraries.

Developers can work separately and focus on writing code instead of document formatting.

8

Tag syntax is specified by means of Tag Library Descriptor (TLD)

TLD specifies tag names, classes and tag attributes.

TLD is an XML document.

Tags are made available within a JSP page via the taglib directive:

<%@ taglib uri=”uri” prefix=“prefix”>

Directive’s prefix attribute provides a local namespace for the TLD’s tags.

At the translation phase all “tld” files referred using taglib directive are loaded.

Tag Handler classes are executed at Request processing phase.

Steps

1) When JSP page is compiled all taglib directives are processed and the “MindTree.tld” is loaded and syntax validation of attributes takes place.

2) Page Execution: When using custom tags JSP compiler checks if it is configured using <%@ taglib %> directive

3) The given tag “employee” is mapped to Tag Handler class “com.mindtree.tags.EmpTag” present in MindTree.tld file.

4) Tag Handle “EmpTag” is executed.

9

Steps :

1) JSP page obtains an reference to tag handler class (instantiates)

2) JSP page invokes setPageContext(), to set the page context. PageContext object encapsulates all the implicit JSP objects (Variables)

3) Pass a parent tag to tag handler class.

4) Invoke setters for all the attributes of a tag.

5) Invoke doStartTag(), to prompt the tag handler to process the start tag for this instance

6) Invoke doEndTag(), after returning from doStartTag()

7) Perform any necessary clean up in release().

10

Basic tags implement the Tag interface

Generate page content

Conditionally execute body content

Conditionally halt page execution

TagSupport class provides default implementation

Tags access JSP environment via the PageContext object pageContext instance variable.

Accessing implicit objects:

pageContext.getRequest()

pageContext.getResponse()

pageContext.getOut()

For tag class examples refer: http://java.sun.com/developer/technicalArticles/xml/WebAppDev3/

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25