Introduction
|
Custom tags are distributed in a tag library, which defines a set of related custom tags and contains the objects that implement the tags. The object that implements a custom tag is called a tag handler.
- JSP technology defines two types of tag handlers: simple and classic.
- Simple tag handlers can be used only for tags that do not use scripting elements in attribute values or the tag body.
- Classic tag handlers must be used if scripting elements are required.
CLICK HERE to download this complete example (zip file)
|
|
CopyrightTag.java
|
-
package copyright;
-
import javax.servlet.jsp.*;
-
import javax.servlet.jsp.tagext.*;
-
public class CopyrightTag extends TagSupport
-
{
-
public int doStartTag() throws JspException
-
{
-
Try
-
{
-
JspWriter out=pageContext.getOut();
-
out.println("<BR><B> Copyright 2008-2009 Bourgia<B>");
-
}
-
catch (Exception ioException)
-
{
-
System.err.println("IO Exception");
-
System.err.println("ioException.toString()");
-
}
-
return SKIP_BODY;
-
}
-
public int doEndTag() throws JspException
-
{
return SKIP_PAGE;
}
}
Download: CopyrightTag.java
|
CopyrightTag.tld
|
-
<taglib>
-
<tlib-version>1.0</tlib-version>
-
<jsp-version>1.2</jsp-version>
-
<short-name>Copyright Info</short-name>
-
<description>
-
Developing First Custom Tags
-
</description>
-
<tag>
-
<name>CopyrightTag</name>
-
<tag-class>copyright.CopyrightTag</tag-class>
-
<body-content>empty</body-content>
-
</tag>
-
</taglib>
Download: CopyrightTag.tld
|
CopyrightTag.jsp
|
-
<html>
-
<head>
-
<title>New Tech Books </title>
-
</head>
-
<body>
-
<center> <b> www.completetutorials.googlepages.com </b> </center><BR>
-
<center><b> Welcome to our Website </b></center>
-
<%@ taglib uri="/CopyrightTag.tld" prefix="chrt" %>
-
<center><chrt:CopyrightTag /></center>
-
</body>
-
</html>
Download: CopyrightTag.jsp
|
|
Click Next To Continue ...
|
|