Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple tags

 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
From HFSJ page 503,I implemented all codes .

Taghandler class

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.*;

public class SimpleTagTest1 extends SimpleTagSupport
{
public void doTag() throws JspException,IOException
{
getJspContext().getOut().print("This is simple use of custom tag");

}

}

TLD file

<?xml version="1.0" encoding="ISO-8859-1"?>
<taglib 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"
version="2.0">
<tlib-version>1.2</tlib-version>
<uri>simpleTags</uri>
<tag>
<description>marginally better use of custom tag</description>
<name>simple1</name>
<tag-class>SimpleTagTest1</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>

JSP code

<%@ taglib prefix="myne" uri="simpleTags" %>

<html>
<body>
<myne:simple1 />
</body>
</html>

But after deployment I got following errors:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 5 in the jsp file: /chkSimpleTag.jsp
SimpleTagTest1 cannot be resolved to a type
2:
3: <html>
4: <body>
5: <myne:simple1 />
6: </body>
7: </html>

Can anyone tell me what am I missing?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you put your tag handler class ? (SimpleTagTest1.class)
 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I put it under WEB-INF/classes folder.
 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I put it under WEB-INF/classes folder.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to put the tag class in a package, instead of the default package.
For example :

and in the tld :
 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe ,
I got it.Thanks.Why with out packages it not working?Is there any reason?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From JSP2.0, using the default package has become "illegal".

JSP Specification,
- Made it illegal to refer to classes in the unnamed (a.k.a. default) package, since JDK 1.4 has stopped supporting this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic