• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jsp Custom Tag  RSS feed

 
Gopinath Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai all

i want to create JSP custom tag of my own. Pls any one tell me how to create JSP custom tag. If possible pls give be code and pls explain it. So that i can learn

regards
Gopi
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Custom tags are covered in the J2EE tutorial... what would you like to do with your tags? We could probably supply some pointers...
 
Krishna Srinivasan
Ranch Hand
Posts: 1880
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code will help you to write custom tags :

tld file
========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.2</jspversion>
<shortname>html</shortname>
<tag>
<name>text</name>
<tagclass>org.custom.tags.TextField</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>


tag class
==========

package org.custom.tags;

import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;

public class TextField extends TagSupport{

private String strProperty = null;

public void setProperty(String property){
this.strProperty = property;
}

public String getProperty(){
return this.strProperty;
}

public int doStartTag(){
try{
JspWriter outStream = pageContext.getOut();
System.out.println("jhsdk");
outStream.println("<input type='text'>");
}catch(Exception exception){
}
return EVAL_PAGE;
}

}

jsp file
=========
<%@ page import="java.util.ArrayList"%>

<%@ taglib uri="/tags/custom-html" prefix="html" %>

<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../theme/Master.css" rel="stylesheet" type="text/css">
<TITLE>tag.jsp</TITLE>
</HEAD>
<BODY>
<table width="100%">

<html:text/>

</table>


</BODY>
</HTML>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!