aspose file tools*
The moose likes JSP and the fly likes JSP Custom Tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Custom Tags" Watch "JSP Custom Tags" New topic
Author

JSP Custom Tags

Robert Darling
Ranch Hand

Joined: Jun 21, 2008
Posts: 100

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30548
    
152

Sajjad,
Sun's tutorial is a good starting point.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Robert Darling
Ranch Hand

Joined: Jun 21, 2008
Posts: 100

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

Joined: Jun 21, 2008
Posts: 100

the index.jsp contains the following code

[ June 29, 2008: Message edited by: Sajjad Dar ]
Robert Darling
Ranch Hand

Joined: Jun 21, 2008
Posts: 100

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

Joined: Jan 10, 2002
Posts: 61239
    
  66

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 .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61239
    
  66

First thing I would to would be to move the tag handler class to a package other than the default.
Robert Darling
Ranch Hand

Joined: Jun 21, 2008
Posts: 100

thanks Bear. Still the same error. Is the directory structure fine.
Shikhar Madhok
Ranch Hand

Joined: Dec 18, 2006
Posts: 95
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


He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever - Chinese proverb
Robert Darling
Ranch Hand

Joined: Jun 21, 2008
Posts: 100

THANKS A BILLION ITS WORKING NOW.
 
Don't get me started about those stupid light bulbs.
 
subject: JSP Custom Tags