How to Create JSP Custom Tag – using BodyTag interface or BodyTagSupport

Author posted by Jitendra on Posted on under category Categories JAVA, JSP and tagged as Tags with 2 Comments on How to Create JSP Custom Tag – using BodyTag interface or BodyTagSupport

Tutorial on How to Create JSP Custom Tag – using BodyTag interface or BodyTagSupport

In Previous articles, i have explained:

Life Cycle of JSP “Tag” interface.

Life Cycle of JSP “BodyTag” interface.

How to Create JSP Custom Tag – using Tag interface or TagSupport

we have seen that how to create the custom JSP tag using interface “Tag”, means tags which does not have a body. In this article, I will explain creating custom Tags which have a body. We can manipulate the content of body as we want.

How to Create Custom Tag in JSP
How to Create Custom Tag in JSP

Continue reading “How to Create JSP Custom Tag – using BodyTag interface or BodyTagSupport”

How to Create JSP Custom Tag – using Tag interface or TagSupport

Author posted by Jitendra on Posted on under category Categories JAVA, JSP and tagged as Tags with 2 Comments on How to Create JSP Custom Tag – using Tag interface or TagSupport

Tutorial of creating JSP Custom Tag – using Tag interface or TagSupport in JAVA

In Previous two articles, i have explained:

Life Cycle of JSP “Tag” interface.

Life Cycle of JSP “BodyTag” interface.

This article is about creating custom Tag in JSP using “Tag” interface.
Creating custom tag in JSP has its unique advantages. This is same as Custom controls of the ASP.Net.
By creating the Custom tag, we can resuse that tag every where in our application. Best example of custom tags are the Struts.

Types of Tag:
Tag without body:

<ct:showTime displayTime="false" />

Tag with body:

<ct:showTime displayTime="false" >
Current Time is :
</ct:showTime>

As ther are two types of tag, there are two way of creating them in JSP:

  • By implementing below interfaces:
    1. Tag
    2. BodyTag
  • Or by extending any of the two below class (provides default implementation of interfaces discussed above):
    1. TagSupport (internally implements Tag)
    2. BodyTagSupport (internally implements BodyTag)

In this article, I will use the interface approach, so that the beginners can get broader idea about how Tag library actually implemented.

How to Create Custom Tag in JSP
How to Create Custom Tag in JSP

Continue reading “How to Create JSP Custom Tag – using Tag interface or TagSupport”

Life cycle of JSP BodyTag interface

Author posted by Jitendra on Posted on under category Categories JSP and tagged as Tags with 3 Comments on Life cycle of JSP BodyTag interface

Life cycle of JSP BodyTag interface

Previous article was about the life cycle of “Tag” interface, in this article i am going to explain the life cycle of “BodyTag” interface.

The BodyTag interface extends IterationTag by defining additional methods that let a tag handler manipulate the content of evaluating its body.

Life cycle of IterationTag and BodyTag interface in JSP
Life cycle of IterationTag and BodyTag interface in JSP

Continue reading “Life cycle of JSP BodyTag interface”

Life cycle of JSP Tag interface

Author posted by Jitendra on Posted on under category Categories JSP and tagged as Tags with 3 Comments on Life cycle of JSP Tag interface

Life cycle of JSP Tag interface in Java

Tag interface:
The interface of a classic tag handler that does not want to manipulate its body. The Tag interface defines the basic protocol between a Tag handler and JSP page implementation class.

Properties:
The Tag interface specifies the setter and getter methods for the core pageContext and parent properties.

Methods:
There are two main actions: doStartTag and doEndTag. Once all appropriate properties have been initialized, the doStartTag and doEndTag methods can be invoked on the tag handler. Between these invocations, the tag handler is assumed to hold a state that must be preserved. After the doEndTag invocation, the tag handler is available for further invocations (and it is expected to have retained its properties).

Empty and Non-Empty Action:
If the TagLibraryDescriptor file indicates that the action must always have an empty action, by an entry of “empty”, then the doStartTag() method must return SKIP_BODY.
Otherwise, the doStartTag() method may return SKIP_BODY or EVAL_BODY_INCLUDE.

If SKIP_BODY is returned the body, if present, is not evaluated.
If EVAL_BODY_INCLUDE is returned, the body is evaluated and “passed through” to the current out.

Life Cycle:

Life Cycle of Tag Interface
Life Cycle of Tag Interface

Continue reading “Life cycle of JSP Tag interface”

Setup application to use JavaServer Pages Standard Tag Library(JSTL)

Author posted by Jitendra on Posted on under category Categories JSP and tagged as Tags , with Leave a comment on Setup application to use JavaServer Pages Standard Tag Library(JSTL)

Setup application to use JavaServer Pages Standard Tag Library(JSTL)

To check whether JSTL is supported by your web container or not, run below code in jsp page:

Simple Test for JSTL Support: ${1+1}
<c:out value="${1+1}" />

With taglib url as :

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

Or

<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

Continue reading “Setup application to use JavaServer Pages Standard Tag Library(JSTL)”

Step by Step DWR Application – Simple AJAX in JAVA

Author posted by Jitendra on Posted on under category Categories JSP, Servlet and tagged as Tags , , with 18 Comments on Step by Step DWR Application – Simple AJAX in JAVA

Step by Step DWR Application – Simple AJAX in JAVA

In this article, i am going to explain the step by step approach to create the DWR (Direct Web Remoting) application in JAVA.

DWR consists of two main parts:

  • A Java Servlet running on the server that processes requests and sends responses back to the browser.
  • JavaScript running in the browser that sends requests and can dynamically update the webpage.
How DWR works in Java
How DWR works in Java

Continue reading “Step by Step DWR Application – Simple AJAX in JAVA”