• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Custom Tags

 
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to write a simple custom tag <temperature:fahrenhite>32</temperature:fahrenhite>

is there any good tutorial that i can follow to do this.

Kind Regards,
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sajjad,
Sun's tutorial is a good starting point.
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.. tried writing the app but came up with errors. Here is what i did.
My tomcat web apps directory contains a folder TagsTest. This parent folder contains 2 files. 1)index.jsp and WEB-INF.
WEB-INF contains the following files.

1)classes folder ===> contains TemperatureTag.class
2)web.xml
3)temperature.tld

Heres contents of TemperatureTag file

==========================================================================

=========================================================================
temperature.tld has the following entries
[code]
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>
<tlibversion>0.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>message</shortname>
<tag>
<name>temperature</name>
<tagclass>TemperatureTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>celcius</name>
<required>true</required>
</attribute>
</tag>
</taglib>
[code]
=========================================================================

When i run the app it gives an error cannot resolve syymbol TemperatureTag. What ami doing wrong.
[ June 29, 2008: Message edited by: Sajjad Dar ]
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the index.jsp contains the following code

[ June 29, 2008: Message edited by: Sajjad Dar ]
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the error thats shown. seems like tomcat cannot find the class

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

An error occurred at line: 6 in the jsp file: /index.jsp

[ June 29, 2008: Message edited by: Sajjad Dar ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First thing I would to would be to move the tag handler class to a package other than the default.
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Bear. Still the same error. Is the directory structure fine.
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please try extending the TagSupport class instead of the BodyTagSupport. You will also have to change the method name to doStartTag()
I am taking a wild guess that this could be an issue since your tag does not actually have a body.
Or another alternative would be to try using your tag like

This would just fool the body tag support class into thinking that your tag has a body.
Or another option may be to change the return to SKIP_BODY instead of EVAL_PAGE.

Try to go through the example again and look at creating a simple tag with attribute since your tag does not really have a body.

HTH
Shikhar
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS A BILLION ITS WORKING NOW.
reply
    Bookmark Topic Watch Topic
  • New Topic