2

I was encountering An error occurred at line: 384 in the generated java file The code of method

_jspService(HttpServletRequest, HttpServletResponse)

is exceeding the 65535 bytes limit.

I have tried several solution around the web and issue still persists.

I am using Jboss-5.1.0 GA as the server.

Here are the stacktrace of the error.

An error occurred at line: 384 in the generated java file
The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

    Stacktrace:
            at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
            at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
            at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
            at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
            at org.apache.jasper.compiler.Compiler.compile(Compiler.java:313)
            at org.apache.jasper.compiler.Compiler.compile(Compiler.java:300)
            at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
            at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543)
            at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480)
            at com.liferay.portlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:307)
            at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:115)
            at com.liferay.portal.struts.PortletRequestProcessor.doInclude(PortletRequestProcessor.java:284)
            at com.liferay.portal.struts.PortletRequestProcessor.doForward(PortletRequestProcessor.java:255)
Jay Thakkar
  • 1,392
  • 10
  • 19

2 Answers2

5

Your JSP is too large / too complicated. You need to refactor it.

We tried refactoring but its not working are there any alternate solutions?

No. There are no alternative solutions.

The problem is that there is a hard limit imposed by the Java Virtual Machine Specification (JVMS) on the number of bytes of bytecode in a compiled Java method. Specifically, the classfile format uses a 16 bit number as the size of the method's code array.)

Java compilers are not able to automatically split a method that is too large into sub-methods. You have to do it yourself at the source code level.

With JSPs, the JSP compiler translates each JSP into a class with a single (large) Java method, unless you can refactor it by either moving some of logic into separate methods, classes or ... JSPs using "dynamic includes"; see https://stackoverflow.com/a/5484509/139985.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks @Stephen for the reply..when I try to use dynamic include instead of include directive it is throwing a classnotfoundexception. can you please suggest me any other alternative ways. – Jeevana Anubrolu Oct 24 '19 at 13:09
  • I don't know any other alternatives apart from the two that I have mentioned. I suggest you figure out **why** you are getting `ClassNotFoundException` and try to fix that. – Stephen C Jan 03 '22 at 00:06
0

This problem can be solved by following the below approach

In your tomcat server, locate the web.xml configuration file (path : tomcat_home/conf/web.xml)

Then search for "JspServlet" block

Now add the below mentioned "<init-param>" value

<init-param>
     <param-name>mappedfile</param-name>
     <param-value>false</param-value>
</init-param> 

After this change your "JspServlet" block will look like this

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
        <param-name>fork</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>xpoweredBy</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>mappedfile</param-name>
        <param-value>false</param-value>
    </init-param> 
    <load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    <url-pattern>*.jspx</url-pattern>
</servlet-mapping>

Save the file and restart the Tomcat server

Sathish
  • 1,481
  • 5
  • 20
  • 33