Pages

Ads 468x60px

Friday 21 December 2012

WEEK-14:to implement custom tag libraries in JSP





Experiment :14
 

Aim : Write a program to implement custom tag libraries in JSP



 Description :

Program :
First.jsp
<%@ taglib uri="hello" prefix="examples"%>
<html>
<head>
<title>First Custom tags</title>
</head>
<body>
<i><examples:hello/>
</i>
</body>
</html>
           
Web.xml
<web-app>
<taglib>
<taglib-uri>hello</taglib-uri>
<taglib-location>/WEB-INF/tlds/hello.tld</taglib-location>
</taglib>
</web-app>

Create a folder called tlds in WEB-INF directory.
Hello.tld

<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<tag>
<name>hello</name>
<tag-class>tagext.HelloTag</tag-class>
<body-content>JSP</body-content>
</tag>
</taglib>




HelloTag.java

package tagext;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.*;
public class HelloTag extends TagSupport
{
   public  int doStartTag()
            {
            return EVAL_BODY_INCLUDE;
            }
            public int doEndTag()
            {
Date date=new Date();
try
{
            pageContext.getOut().write("HellOWorld");
            pageContext.getOut().write("My name is :"+getClass().getName()+"and it's"+date);
}catch(Exception e){}
return EVAL_PAGE;
}
}


Output

http://wikibrand.blogspot.in


Result :

Thus the implementation of custom  tag libraries in JSP is done.

0 comments:

Post a Comment

 

Sample text

Sample Text

Sample Text