The JSP compiler cannae take it Cap'n
We ran into the old Java method limit problem compiling a JSP the other day. In the webapp log file we saw
org.apache.jasper.JasperException: Unable to compile class for JSP Generated servlet error: The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit
and a little further down
... at org.apache.jsp.display.main.content_jsp._jspService(content_jsp.java:2965) ...
The JSPs had tested okay on our staging environment but had failed when deployed to production. I assumed that content.jsp was causing the error and that, as it was a large JSP with lots of static includes, it was white space that was pushing it over the limit.
It turned out to be a runtime include that took a dynamic URL string. So the problem only occurred on certain versions of the page.
<jsp:include page="<%=cpUrl%>" flush="true"/>
I wanted to compile the JSP myself to see the error. On Tomcat if you look under the tomcat/work/Catalina directory you can find the “servlets” that get generated by Tomcat. If you see any .java without a corresponding .class it is a sign that the compilation failed. You can compile the generated .java file. If the file has been generated by Tomcat You will need to include the following jars in your classpath as well as any application jars or classes on which your JSP depends.
- common/lib/jasper-runtime.jar
- common/lib/servlet-api.jar
- common/lib/jsp-api.jar
Of course relying on the trimSpaces parameter to sneak your JSPs under the 64K limit is poor design
<servlet> ... <init-param> <param-name>trimSpaces</param-name> <param-value>true</param-value> </init-param> </servlet>
The real lesson is to structure your JSP correctly so that the service method is not too big. However I've written this up in the hope it might be useful for solving other errors.