• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error using taghandler, why does it not work?  RSS feed

 
northfield Sid
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on Tag-Handlers with JSP getting some errors:
/* This is a taghandler class
*/
package simpletag;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class SimpleTag extends javax.servlet.jsp.tagext.TagSupport
{
public int doStartTag() throws JspException
{
try
{
pageContext.getOut().print("Welcome to my Web site.");
}
catch (Exception e)
{
throw new JspTagException(e.getMessage() );
}
return SKIP_BODY;
}
}
Here is a very simple "usertag.jsp" which is located at:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\Whitehead\chap10
<html>
<head>
<title> Tag example</title>
</head>
<body>
<%@ taglib uri=""http://www.maran.com/taglib" %>
<myTags:simpletag.simpleTag></myTags:simpletag.simpleTag>
</body>
</html>
I have writtentag library descriptor called "taglib.tld" this is located in the following directory:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\classes\simpletag
Is this correct? the book I am using does not mention where to put my "tablib.tld"
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTDT JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.1</tlibversion>
<jspversion>1.1</jspversion>
<shortname>MyFirstTag</shortname>
<info>My first tag library descriptor file</info>
<tag>
<name>SimpleTag</name>
<tagclass>simpletag.SimpleTag</tagclass>
</tag>
</taglib>
The book mentions I need to add some code to a class called "web.xml"
I have decided to edit the web.xml file located at D:\tomcat\jakarta-tomcat-3.3.1\webapps\ROOT\WEB-INF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<taglib>
<taglib-uri>
http://www.maran.com/taglib
<taglib-uri>
<taglib-location>
/WEB-INF/classes/simpletag/taglib.tld
</taglib-location>
</taglib>
</web-app>

<taglib>
<taglib-uri>
http://www.maran.com/taglib
<taglib-uri>
<taglib-location>
/WEB-INF/classes/simpletag/taglib.tld
</taglib-location>
</taglib>
Here is the error:
Error: 500
Location: /myJSPs/jsp/Whitehead/chap10/usetag.jsp
Internal Servlet Error:
org.apache.jasper.compiler.ParseException: D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\Whitehead\chap10\usetag.jsp(5,23) Attribute http: has no value
at org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader.java:528)
at org.apache.jasper.compiler.JspReader.parseTagAttributes(JspReader.java:644)
at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:192)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1077)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1042)
at org.apache.jasper.compiler.Parser.parse(Parser.java:1038)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:209)
at org.apache.tomcat.facade.JasperLiaison.jsp2java(JspInterceptor.java:790)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:731)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:484)
Here is the usetag.jsp
<html>
<head>
<title> Tag example</title>
</head>
<body>
<%@ taglib uri=""http://www.maran.com/taglib" %>
<myTags:simpletag.simpleTag></myTags:simpletag.simpleTag>
</body>
</html>
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The taglib tld files are normally placed somewhere under the webapps WEB-INF directory tree where they will be hidden from unfriendly eyes.
Here's a taglib reference from a JSP:

And here's the corresponding clause from the web.xml file that causes the URI to matchup to the actual taglib location (which for this example is the same as the URI):
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!