Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Custom Tags

 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
 
Robert Darling
Ranch Hand
Posts: 100
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64855
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks Bear. Still the same error. Is the directory structure fine.
 
Shikhar Madhok
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
THANKS A BILLION ITS WORKING NOW.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic