Jeevana Anubrolu
Jeevana Anubrolu

Reputation: 41

How to fix the error The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit Jboss

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)

Upvotes: 4

Views: 15260

Answers (3)

Stephen C
Stephen C

Reputation: 719239

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

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.)


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

No. There are no alternative solutions. (As far as I know.)

When I try to use dynamic include instead of include directive it is throwing a ClassNotFoundException.

That means that you made a mistake in your refactoring ... not that refactoring won't work. (You have apparently introduced a reference to a Java class with the wrong name, package or something. Or you haven't included it in class libraries that the JSP compiler has been told about.)

Upvotes: 6

Sardaar54
Sardaar54

Reputation: 36

I faced a similar issue when I had to import a large js file onto my jsp file. I resolved the issue by adding the following lines in web.xml file of my project:

<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> 

Upvotes: 1

Sathish
Sathish

Reputation: 1521

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

Upvotes: 0

Related Questions