Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP Custom Tags How to?

Status
Not open for further replies.

puntito

Programmer
Mar 22, 2006
18
I have to learn how to create custom tags.
I am using MyEclipse.

I create the class

Code:
 public class etiqts extends TagSupport {
	
    
	public etiqts() {
		super();
		// TODO Auto-generated constructor stub
	}

	public int doStartTag() throws JspException {
        try {
        	pageContext.getOut().print("Esta es mi etiqueta");
        } catch (IOException e){
            throw new JspException("Error al enviar al cliente" + 
                                            e.getMessage());
        }
        return SKIP_BODY;
    }
	public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }
	
    public void release(){
    }

Then the tag library


Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib
    PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
	"[URL unfurl="true"]http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">[/URL]
<taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>tagFile</shortname>
    <uri></uri>
    <info>Etiquetas de ejemplo</info>
	
    <tag>
    <name>etiquets</name>
        <tagclass>etiqts</tagclass>
        <bodycontent>empty</bodycontent>
        <info>Saludo</info>
    </tag>
</taglib>

And the jsp page

Code:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib uri="tagFile.tld" prefix="tagFile" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'probandoTag.jsp' starting page</title>
  </head>
  
  <body>
    This is my JSP page with a tag. <br>
    <tagFile:etiquets/>
    
  </body>
</html>


But I'm not sure, why it doesnt work
Could somebody give me any advise, please??
Thanks!!
 
Hi

What that "it doesnt work" means ? Gives error, generate broken content, make nothing ? Got any error message in the generated document, IDE's console, log file ?

Feherke.
 
Have you registered the tagFile.tld location at the web.xml?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top