• Post Reply Bookmark Topic Watch Topic
  • New Topic

SimpleSupportTag problem  RSS feed

 
david cotter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

Thanks for your help last time but alas, I have another problem.

I am trying to create my own custom tag. it's real simple but the JSP using the Tag won't complie. It appears the compiler cannot resolve symbols:

symbol : method setPageContext (javax.servlet.jsp.PageContext)
symbol : method setParent (<nulltype>
symbol : method doStartTag ()
symbol : method doEndTag ()

(full exception stack below)

These methods do not exist in SimpleSupportTag which my Tag handler extends.
Could I have the wrong version of something?

SimpleTagSupport is in the jar:
jsp-api.jar:
Name: javax/servlet/jsp/
Specification-Title: Java API for JavaServer Pages
Specification-Version: 2.0

Tomcat 5.0.28
J2RE 1.4.1_02
Servlet-api 2.4


============ tagtest.jsp: ============

<%@ taglib prefix="myTagHandlers" uri="simpletag" %>

<html>
<title>Tag Test</title>
<body>
The advice is: <myTagHandlers:hello/>
</body>
</html>


============ AdviceTagHandler class: ============

public class AdviceTagHandler extends SimpleTagSupport
{
public void doTag() throws JspException, IOException
{
getJspContext().getOut().println("we are in the doTag() method!");

}
}

============ TLD definition: ============

<tlib-version>1.2</tlib-version>
<uri>simpletag</uri>

<tag>
<name>hello</name>
<tag-class>com.headfirst.tags.AdviceTagHandler</tag-class>
<body-content>empty</body-content>
</tag>


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

Exceptions when I try to view the JSP in the browser:

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

An error occurred at line: 8 in the jsp file: /pages/tagtest.jsp
Generated servlet error:
C:\Program Files\Apache Group\jakarta-tomcat-5.0.28\work\Catalina\localhost\beerApp\org\apache\jsp\pages\tagtest_jsp.java:89: cannot resolve symbol
symbol : method setPageContext (javax.servlet.jsp.PageContext)
location: class com.headfirst.tags.AdviceTagHandler
_jspx_th_myTagHandlers_hello_0.setPageContext(_jspx_page_context);
^


An error occurred at line: 8 in the jsp file: /pages/tagtest.jsp
Generated servlet error:
C:\Program Files\Apache Group\jakarta-tomcat-5.0.28\work\Catalina\localhost\beerApp\org\apache\jsp\pages\tagtest_jsp.java:90: cannot resolve symbol
symbol : method setParent (<nulltype>
location: class com.headfirst.tags.AdviceTagHandler
_jspx_th_myTagHandlers_hello_0.setParent(null);
^


An error occurred at line: 8 in the jsp file: /pages/tagtest.jsp
Generated servlet error:
C:\Program Files\Apache Group\jakarta-tomcat-5.0.28\work\Catalina\localhost\beerApp\org\apache\jsp\pages\tagtest_jsp.java:91: cannot resolve symbol
symbol : method doStartTag ()
location: class com.headfirst.tags.AdviceTagHandler
int _jspx_eval_myTagHandlers_hello_0 = _jspx_th_myTagHandlers_hello_0.doStartTag();
^


Generated servlet error:
C:\Program Files\Apache Group\jakarta-tomcat-5.0.28\work\Catalina\localhost\beerApp\org\apache\jsp\pages\tagtest_jsp.java:92: cannot resolve symbol
symbol : method doEndTag ()
location: class com.headfirst.tags.AdviceTagHandler
if (_jspx_th_myTagHandlers_hello_0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE)
^


Generated servlet error:
C:\Program Files\Apache Group\jakarta-tomcat-5.0.28\work\Catalina\localhost\beerApp\org\apache\jsp\pages\tagtest_jsp.java:94: reuse(javax.servlet.jsp.tagext.Tag) in org.apache.jasper.runtime.TagHandlerPool cannot be applied to (com.headfirst.tags.AdviceTagHandler)
_jspx_tagPool_myTagHandlers_hello_nobody.reuse(_jspx_th_myTagHandlers_hello_0);
^
5 errors



org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These methods do not exist in SimpleSupportTag which my Tag handler extends.
Could I have the wrong version of something?


Those methods indeed do not exist for simple tags. They are methods in the "classic" tag support classes. If you want to use SimpleTagSupport, you need to conform to its API. If you want to use the methods you have outlined, you need to use the "classic" TagSupport class.
 
david cotter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to re-create an example for Simple tags (the example is a more-or-less direct copy of the example given in Headfirst Servlets & JSP book). I am extending SimpleTagSupport and overriding doTag(). I don't particularly want to use the methods that are causing problems. In fact I wasn't even aware of them until Jasper complained. They are appearing in the JSP's generated servlet. I'm not sure what to do ...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the problem is not when compiling your tag handlers, but when the JSP gets compiled?

Post you JSP code (be sure to use UBB code yags to preserve the formatting), your TLD, and the tag handler code.
 
david cotter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the problem is when the JSP attempts to compile. The source for the JSP, Tag handler class and TLD definition is with my original request for this problem (above). Also the stack trace of the exception. Jasper generates the rogue methods in the compiled servlet. I don;t know why they're necessary.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I was actually hoping you'd repost the code or go back and edit the original with UBB code tgas to make the code more readable...

This is odd. It almost looks like Tomcat is not recognizing your tags as SimpleTags.

Grasping here, but did you delcare your TLD using JSP 2.0 mechanisms? Here's an example from one of my TLDs that works flawlessly in Tomcat 5.0.25:


[ July 05, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, does your web.xml declare your web app as a Servlet 2.4 web app?


[ July 05, 2005: Message edited by: Bear Bibeault ]
 
david cotter
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed my taglic to the following and it worked:

[UBB]
<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_4.xsd"
version="2.4">

[/UBB]

Previously, it declared version="2.0"

It doesn't make a lot of sense to me but it works now so I'm happy.

Thanks for your help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!