• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

simple tags

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I put it under WEB-INF/classes folder.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic