SET AS HOME PAGE

ADD TO FAVORITES / BOOKMARK THIS WEBSITE (More Details)

Introduction

Servlet

Jsp

Security

Enterprise Beans

Contact Us


JSP Custom Tags And Design Patterns

 Introduction

A custom tag is a user-defined JSP language element. When a JSP page containing a custom tag is translated into a servlet, the tag is converted to operations on a tag handler. The web container then invokes those operations when the JSP page’s servlet is executed.

Custom tags have a rich set of features. They can
  • Be customized via attributes passed from the calling page.
  • Pass variables back to the calling page.
  • Access all the objects available to JSP pages.
  • Communicate with each other. You can create and initialize a JavaBeans component, create a public EL variable that refers to that bean in one tag, and then use the bean in another tag.
  • Be nested within one another and communicate via private variables.

 Custom Tag API

The following table describes various classes of the javax.servlet.jsp.tagtext package:

ClassDescription
BodyContent Is a subclass of the JSPWriter class and represents the body content of a tag.
TagSupport Acts as a base class for tag handlers and implements empty tags.
BodyTagSupport Implements the BodyTag interface. This class is used to develop custom tags with body.
TagData Represents the attributes and their values.
TagInfo Represents the information specified in the <tag></tag> element of the TLD file. This class is used by the JSP engine while translating a JSP page to a servlet
TagLibraryInfo Represents the information of the TLD file, such as the tags it defines and versioning information.
TagVariableInfo Represents information about the variables of a custom tag.


The following table describes various methods that you can implement in a tag handler:

Method Description
public int doStartTag() Defined by the Tag interface. This method is invoked when the start tag of the custom tag is encountered. The doStartTag() method returns the SKIP_BODY value to specify that the processing of the body content should be skipped. This method can also return EVAL_BODY_INCLUDE value to specify that the body content of the tag should be processed.
public void release() Defined by the Tag interface. This method is invoked to allow the tag handler to release some of its resources.
doAfterBody() Implemented by the BodyTagSupport class. This method is invoked after the body tag is evaluated. The doAfterBody() method returns the EVAL_BODY_AGAIN value to specify that the body content should be reevaluated. This method can also return SKIP_BODY value to specify that the evaluation of the body content should be skipped.
public int doEndTag() Defined by the Tag interface. This method is invoked when the end tag of a custom tag is encountered. The doEndTag() method returns the EVAL_PAGE value to process the remaining JSP page or the SKIP_PAGE value to skip the processing of the remaining page.


The following table describes some important methods of the PageContext class:

Method Description
public abstract JspWriter getOut() Returns the JSP implicit object, out.
public abstract ServletRequest getRequest() Returns the JSP implicit object, request.
public abstract ServletResponse getResponse() Returns the JSP implicit object, response.
public abstract HttpSession getSession() Returns the JSP implicit object, session
public abstract Exception getException() Returns the JSP implicit object, exception
public abstract ServletContext getServletContext() Returns the JSP implicit object, application
public abstract ServletConfig getServletConfig() Returns the JSP implicit object, config
public abstract Object getPage() Returns the JSP implicit object, page



 Click for Next Topic
<- PREVIOUSNEXT ->