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

ServletException after JSP precompilation

Todd Farmer
Ranch Hand

Joined: May 28, 2004
Posts: 59
I have been attempting to pre-compile my JSP files in Tomcat 5.0. I am using Struts with Tiles, and my JSP files are all contained under the WEB-INF folder, so they are not directly accessible. Some of the pages work fine after the pre-compilation, but others do not. Specifically, I get a ServletException that looks something like this:



Any idea why this may be happening? The exception information is not particularly helpful.


Thanks!

Todd Farmer
Todd Farmer
Ranch Hand

Joined: May 28, 2004
Posts: 59
I've managed to compare the .java files created by JSPC in the precompilation step to the .java files created when I deply the .jsp files as part of my WAR file. I've found the differences that are causing the problem. Here's a snippet from a method in an inner class of one of the .java files created by the JSPC precompilation:



This private inner class extends org.apache.jasper.runtime.JspFragmentHelper, which has a protected field _jspx_page_context (a javax.servlet.jsp.PageContext type).

The .java file created by Tomcat when the same .jsp file is deployed as part of the WAR file looks different, and uses this _jspx_page_context field from the superclass in place of the pageContext variable:



I'm still at a loss as to why the generated .java files are different when using JSPC to precompile the .jsp files and when Tomcat does it during deployment. I'm using the Maven Tomcat plug-in. I may try to use an Ant script to see if I have the same problems, but I don't see any reason to believe I will get different results.

Any suggestions?

Todd Farmer
[ August 17, 2005: Message edited by: Todd Farmer ]
Todd Farmer
Ranch Hand

Joined: May 28, 2004
Posts: 59
I finally figured out the root cause of the problem. It appears that when I precompile .jsp files that contain custom tags, I end up with this problem. Removing the custom tags allows the precompilation to work correctly. The standard Struts and JSTL tags appear precompile fine; it's just my custom tags that do not.

At this point, I have no idea why this is the case. I sure would like to be able to use custom tags and precompilation. I wonder if there is something I am doing wrong, or if I need to register my custom tags somehow with the JSPC step to make this work.

Todd Farmer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Is the jar file containing your custom tags and its tld in the classpath during the pre-compile?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Todd Farmer
Ranch Hand

Joined: May 28, 2004
Posts: 59
That's a really good question. The custom tags I developed haven't been factored out to a separate .jar file (they are under the WEB-INF/classes folder), which is different than the Struts and JSTL code.

I'm using the Maven Tomcat plug-in, so I'm not explicitly setting the classpath for the pre-compile step. I can imagine the loose class files are not being included in the classpath used by the Tomcat plug-in.

I'll try pulling the tags out into a separate .jar file and listing that as a Maven dependency and seeing if that resolves my issue.

Thanks for the good suggestion!

Todd Farmer
Todd Farmer
Ranch Hand

Joined: May 28, 2004
Posts: 59
Well, I pulled the custom tag code out to a separate project and used that .jar file (including the .tld) as a dependency for my web project. When I ran the Maven Tomcat plug-in, I ended up with the same result. Bummer.

I guess it is still possible (OK, likely) that I'm doing something wrong and missing some needed configuration to precompile successfully. I've already upgraded from Tomcat 5.0 to 5.5, and that didn't resolve anything. Next step has to be to try pre-compilation using Ant to try to isolate the Maven Tomcat plug-in, I guess.

Todd Farmer
Todd Farmer
Ranch Hand

Joined: May 28, 2004
Posts: 59
I can tell that the precompile process is able to access the Java code for the custom tags, because the business logic encapsulated in the tags is visible in the precompiled JSPs. It still seems to be naming the PageContext object variable incorrectly.

Odd.

Todd Farmer
 
 
subject: ServletException after JSP precompilation