25
1

Servlet and Jsp Technology -Part4

Embed Size (px)

DESCRIPTION

Servlet and Jsp Technology -Part4

Citation preview

Page 1: Servlet and Jsp Technology -Part4

1

Page 2: Servlet and Jsp Technology -Part4

2

Page 3: Servlet and Jsp Technology -Part4

3

Page 4: Servlet and Jsp Technology -Part4

4

Page 5: Servlet and Jsp Technology -Part4

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

Page 6: Servlet and Jsp Technology -Part4

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

Page 7: Servlet and Jsp Technology -Part4

7

Page 8: Servlet and Jsp Technology -Part4

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

Page 9: Servlet and Jsp Technology -Part4

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

Page 10: Servlet and Jsp Technology -Part4

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

Page 11: Servlet and Jsp Technology -Part4

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

Page 12: Servlet and Jsp Technology -Part4

12

Page 13: Servlet and Jsp Technology -Part4

13

Page 14: Servlet and Jsp Technology -Part4

14

Page 15: Servlet and Jsp Technology -Part4

15

Page 16: Servlet and Jsp Technology -Part4

16

Page 17: Servlet and Jsp Technology -Part4

17

Page 18: Servlet and Jsp Technology -Part4

18

Page 19: Servlet and Jsp Technology -Part4

19

Page 20: Servlet and Jsp Technology -Part4

20

Page 21: Servlet and Jsp Technology -Part4

21

Page 22: Servlet and Jsp Technology -Part4

22

Page 23: Servlet and Jsp Technology -Part4

23

Page 24: Servlet and Jsp Technology -Part4

24

Page 25: Servlet and Jsp Technology -Part4

25