<c:out>
<c:set>
<c:remove>
<c:if>
<c:choose> <c:when> and <c:otherwise>
<c:choose>
<c:when test="${id eq 101}">
id is 101
</c:when>
<c:when test="${id eq 102}">
id is 102
</c:when>
<c:otherwise>
id is not available
</c:otherwise>
</c:choose>
<c:forEach>
<c:import>
<jsp:include page=”header.jsp” />
<c:import url=”header.jsp” />
<c:import url=http://www.google.com />
<c:redirect>
<c:redirect url=”header.jsp” />
<c:redirect url=http://www.google.com />
<c:param>
<c:param name=”myName” value=”Atul” />
<c:import url=”header.jsp”>
<c:param name=”companyName” value=”My Company” />
</c:import>
<c:redirect url=”home.jsp”>
<c:param name=”companyName” value=”My Company” />
</c: redirect>
<c:url>
<c:url value=”hello.jsp” />
<a href=”hello.jsp”>Click Here</a>
<a href=’<c:url value=”hello.jsp” />’>Click Here</a>
<a href=’<%= response.encodeURL(“hello.jsp”)%>’>Click Here</a>
setPageContext()
setParent()
doStartTag()
doEndTag()
release()
EVAL_BODY_INCLUDE
SKIP_BODY
EVAL_PAGE
SKIP_PAGE
setBodyContent()
doInitBody()
We will see an example which demonstrate the how to develop and use JSP Custom Tags. Requirement is to develop a customer tag to greet the user and if no user is specified then communicate the same to the user. To develop custom tag for above mentioned requirement we need one TLD file to specify all tag related information, one Tag handler Java class to handle lifecycle of custom tag and to perform logic on that and finally one JSP file as a starting point of this i.e. from where request can be initiated for custom tag.
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<uri>http://atuldwivedi.com/ctag</uri>
<tag>
<name>greet</name>
<tag-class>com.atuldwivedi.learnjsp.customtag.GreetTagHandler
</tag-class>
<body-content>empty</body-content>
<attribute>
<name>uname</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
package com.atuldwivedi.learnjsp.customtag;
import java.io.IOException;
import java.io.Writer;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
public class GreetTagHandler extends TagSupport {
private static final long serialVersionUID = 1L;
private String uname;
public void setUname(String uname) {
this.uname = uname;
}
@Override
public int doEndTag() throws JspException {
Writer out = pageContext.getOut();
try {
if (uname == null || uname.trim().isEmpty()) {
out.write("You have not specified your name.");
} else {
out.write("Hello " + uname);
}
} catch (IOException e) {
e.printStackTrace();
}
return super.doEndTag();
}
}
public void setBodyContent(BodyContent bodyContent)
public void doInitBody()
EVAL_BODY_BUFFERED
public BodyContent getBodyContent()