This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes simple tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "simple tags" Watch "simple tags" New topic
Author

simple tags

kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

Where did you put your tag handler class ? (SimpleTagTest1.class)


[My Blog]
All roads lead to JavaRanch
kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
Hi
I put it under WEB-INF/classes folder.
kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
Hi
I put it under WEB-INF/classes folder.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Try to put the tag class in a package, instead of the default package.
For example :

and in the tld :
kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
Hi Christophe ,
I got it.Thanks.Why with out packages it not working?Is there any reason?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.
 
Don't get me started about those stupid light bulbs.
 
subject: simple tags
 
Similar Threads
taglib problem in Netbeans
CustomTag
Problems in my code
Simple Tag
cannot find the declaration of element taglib