Saturday, October 20, 2012

Tag library with coustom tag

author.tld
 
   
  1.0  
  au  
  /WEB-INF/tlds/author;  
    
   authorTagHandler  
   handler.authorTagHandler  
   scriptless  
    
   


authorTagHandler.java

 package handler;  
 import javax.servlet.jsp.JspWriter;  
 import javax.servlet.jsp.JspException;  
 import javax.servlet.jsp.tagext.JspFragment;  
 import javax.servlet.jsp.tagext.SimpleTagSupport;  
 public class authorTagHandler extends SimpleTagSupport {  
   @Override  
   public void doTag() throws JspException {  
     JspWriter out = getJspContext().getOut();  
     try {  
       out.println("welcome to my business");  
       JspFragment f = getJspBody();  
       if (f != null) {  
         f.invoke(out);  
       }  
     } catch (java.io.IOException ex) {  
       throw new JspException("Error in authorTagHandler tag", ex);  
     }  
   }  
 }  


index.jsp
 <%--   
   Document  : index  
   Created on : Oct 18, 2012, 8:17:18 PM  
   Author   : UTTAM KASUNDARA  
 --%>  
 <%@page contentType="text/html" pageEncoding="UTF-8"%>  
 <!DOCTYPE html>  
 <html>  
     <head>  
         <title>Your Standard Hello World Demo</title>  
     </head>  
     <body bgcolor="#ffffff">  
       <%@taglib uri="/WEB-INF/tlds/author" prefix="au" %>  
       <au:authorTagHandler></au:authorTagHandler>  
     </body>  
 </html>  



file Structure

output

No comments:

Post a Comment