[TOMCAT] _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

[TOMCAT] _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

 

서버에 jsp 패치 이후 특정 페이지에서 아래와 같이 500 에러가 발생하였다.

우선, 해당 페이지 소스 코드에 이상이 있는지 확인해봤지만 이상 없었다.

 

HTTP Status 500

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

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

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

Stacktrace:
 org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
 org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
 org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:319)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:309)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:688)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.31 logs.

Apache Tomcat/5.5.31

 

 

검색 결과 tomcat 의 conf 폴더 내의 web.xml 을 수정해주면 해결 가능했다.

web.xml 의 <servlet> 태그 안에 아래 코드를 넣고 톰캣을 재기동하면 된다.

참고사이트) https://bulkywebdeveloper.tistory.com/6

 

<servlet>

(중략)

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

(중략)

</servlet>

 

 

 

원인은 jsp 파일 내용이 길어지면서 메서드 길이 제한인 65535 를 초과했기 때문이라고 한다.

아래의 오라클에서 제공하는 페이지를 참고할 것.

참고사이트) https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.11

4. 11. Limitations of the Java Virtual Machine

(중략)

The per-class or per-interface constant pool is limited to 65535 entries by the 16-bit constant_pool_count field of the ClassFile structure (§4.1).

(중략)

The number of fields that may be declared by a class or interface is limited to 65535 by the size of the fields_count item of the ClassFile structure (§4.1).

(중략)

The number of methods that may be declared by a class or interface is limited to 65535 by the size of the methods_count item of the ClassFile structure (§4.1).

(중략)

  

한 편 톰캣에 설정한 mappedfile의 의미는, mappedfile 이 true 일 경우 톰캣 컨테이너가 HTML 코드(jsp 를 컴파일한 결과 코드)를 라인 수 만큼의 out.write 로 출력한다고 한다.

반대로 mappedfile 이 false 일 때는 HTML 코드를 out.write 한 번에 출력한다고 한다.

(When mappedfile is true, container generates “out.print()” for each HTML text line in the JSP file. And when false, the HTML text from multiple lines are concatenated and output in one “out.print()” and that’s how it ease debugging.)

과거 버전인 톰캣 3과 4에서는 mappedfile 디폴트값이 false 인데, 톰캣 5는 mappedfile 디폴트 값이 true 라고 한다.

(Older version of tomcat (3,4) have this option by default false and newer version starting from tomcat 5 have this option default true.)