wood burning stoves 2.0*
The moose likes JSP and the fly likes problem in creating tag library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "problem in creating tag library" Watch "problem in creating tag library" New topic
Author

problem in creating tag library

Krishna Acharya
Ranch Hand

Joined: Jun 05, 2007
Posts: 33
I am creating Hello World program of custom Tag. for this, I have developed following files:
1. Tag Handler: HelloTag.java

package coreservlets.tags;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;

public class HelloTag extends TagSupport {

public int doStartTag() {
try {
JspWriter out = pageContext.getOut();
out.print("Custom tag example " +
"(coreservlets.tags.ExampleTag)");
} catch(IOException ioe) {
System.out.println("Error in ExampleTag: " + ioe);
}

return(SKIP_BODY);
}
}
2. Tag Library Descriptor:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>mytld</short-name>
<uri>/WEB-INF/tags/mytld.tld</uri>
<!-- A validator verifies that the tags are used correctly at JSP
translation time. Validator entries look like this:
<validator>
<validator-class>com.mycompany.TagLibValidator</validator-class>
<init-param>
<param-name>parameter</param-name>
<param-value>value</param-value>
</init-param>
</validator>
-->
<!-- A tag library can register Servlet Context event listeners in
case it needs to react to such events. Listener entries look
like this:
<listener>
<listener-class>com.mycompany.TagLibListener</listener-class>
</listener>
-->

<tag>
<name>myTag</name>
<tagclass>coreservlets.tags.HelloTag</tagclass>
<info>Simplest example: inserts one line of output</info>
<bodycontent>EMPTY</bodycontent>
</tag>

</taglib>

3. JSP file:
<%@ taglib tagdir="/WEB-INF/tags/mytld.tld" prefix="mytld" %>

<HTML>
<HEAD>
<TITLE>Tag Example</TITLE>
</HEAD>

<BODY>
<strong>JSTL Hello World Program </strong>

<H1><mytld:myTag />


</BODY>
</HTML>
Folder structure in tomcat:
root
|
|--index.jsp
|--WEB-INF
|
|--classes
|
|-core-servlets
| |
| |--tags
| |
| |--HelloTag.class
|
|--tags
|
|-mytld.tld
Problem: requested resource is not available... what is the problem?

Please help me: I am in trouble from long time.

Thanks in advance.
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
The exact error message would be more helpful.

It looks like you do not have the tld under WEB-INF...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Please be sure to use UBB code tags when posting code to the forums. Please read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
GeeCON Prague 2014
 
subject: problem in creating tag library