Reputation: 1721
I have a JSP page . With the course of time it has become very long somehow.
Recently i was compiling the jsp page and i got an exception from the compiler that
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 320 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:102)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
What should I do to avoid this exception.?
Upvotes: 3
Views: 6271
Reputation: 1
Resolved the issue.
in standlone.xml, under web subsystem -> configuration add keep-generated=false.
It worked for me.
Upvotes: 0
Reputation: 1109072
During JSP compilation, the entire body of a JSP file will be placed inside a single try
block. The limit which a Java block can contain is 64KB. The size of the generated Java code of your JSP file apparently exceeded that.
Perhaps you have extremely a lot of HTML or conditionals in the JSP file. You need to split the JSP file in smaller parts which you include by <jsp:include>
. For example one JSP include file per header, footer, menu, body and/or conditionally displayed parts, etc. It has the additional advantage that it's better reuseable.
Or, perhaps you followed the discouraged oldschool bad practice of writing raw Java code inside the JSP file using scriptlets (those <% %>
things), while that Java code actually belongs in normal Java classes. Get rid of all that Java code in JSP and move it into a fullworthy servlet class then. Therein you have all the freedom to write nicely reuseable classes/methods instead of putting the entire thing inside one large unmaintainable "God" block.
Upvotes: 6