相关链接:
http://topic.csdn.net/t/20041111/20/3544983.html
http://www.javaeye.com/post/57265
http://www.javaworld.com.tw/jute/post/view?bid=6&id=34678&sty=3
http://marc.info/?l=struts-user&m=98512887614286&w=2
具体问题:
我的JSP文件太大有300多K,这个主要是因为系统一直在维护,很多人因为各种功能需求对这个JSP做了修改,本来编译和运行都是没有问题的,但奇怪的是我只多加了一段HTML代码就出现了这个问题,说了大家可能不信,我只多加了一个<td>kkkee</td>,就出问题了,代码如下:注释的部分是我加的,加了后就出问题:
- <tr>
- <td width="" CLASS="fmkey" valign="top">BuCode:</td>
- <td width="" class="fmvalue" align="left">
- <INPUT TYPE="TEXT" NAME="BuCode" SIZE="23" CLASS="<%=sStyle%>" >
- </span>
- </td>
- <td>
- <INPUT TYPE="BUTTON" NAME="" VALUE=". . ." CLASS="btnLook" onClick="openLookupGen(arrSetBuCode, arrGetBuCode ,'<%=EusUtil.getPage("lookup.generic.bucode.s")%>', arrBuCodeParam, 640, 480, 'yes')">
- sfsfsf
- </td>
- <!-- <td>kkkee</td> -->
-
-
- </tr>
具体问题如下:
- <<2008-12-11 10:19:57.750>> (HttpUtil) ErrorMsg : callpage
- ExceptionMsg: org.apache.jasper.JasperException: Unable to compile class for JSP
- An error occurred at line: -1 in the jsp file: null
- Generated servlet error:
- [javac] Compiling 1 source file
- C:/DOCUME~1/WEIFEN~1/LOCALS~1/Temp/Jetty_0_0_0_0_8080__GeTSmart/Tdec_jsp.java:147: code too large for try statement
- try {
- ^
- 1 error
- at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
- at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
- at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:340)
- at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
- at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
- at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
- at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
- at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
- at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
- at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
- at org.mortbay.jetty.servlet.Dispatcher.dispatch(Dispatcher.java:192)
- at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:129)
- at com.gobusiness.eus.util.HttpUtil.callPage(HttpUtil.java:225)
- at com.gobusiness.eus.servlet.CreateDocServlet.doPost(CreateDocServlet.java:365)
- at com.gobusiness.eus.servlet.CreateDocServlet.doGet(CreateDocServlet.java:76)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
- at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
- at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
- at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
- at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
- at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
- at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
- at org.mortbay.http.HttpServer.service(HttpServer.java:863)
- at org.jboss.jetty.Jetty.service(Jetty.java:460)
- at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)
- at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
- at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
- at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
- at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
- at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
也有出现这个问题:
(Code of a method longer than 65535 bytes)
- ExceptionMsg: javax.servlet.ServletException: org/apache/jsp/Tdec_jsp (Code of a method longer than 65535 bytes)
- at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
- at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
- at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
- at org.mortbay.jetty.servlet.Dispatcher.dispatch(Dispatcher.java:192)
- at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:129)
- at com.gobusiness.eus.util.HttpUtil.callPage(HttpUtil.java:225)
- at com.gobusiness.eus.servlet.CreateDocServlet.doPost(CreateDocServlet.java:365)
- at com.gobusiness.eus.servlet.CreateDocServlet.doGet(CreateDocServlet.java:76)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
- at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
- at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
- at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
- at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
- at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
- at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
- at org.mortbay.http.HttpServer.service(HttpServer.java:863)
- at org.jboss.jetty.Jetty.service(Jetty.java:460)
- at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)
- at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
- at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
- at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
- at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
- at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
查了相关的资料:
http://marc.info/?l=struts-user&m=98512887614286&w=2
这个帖子解释的比较清楚,还提供了相关的办法
- The problem is that there is a limit on the size of a compiled method in a
- Java class file, and that limit is what we're running up against. Recall
- that a JSP page is compiled into a servlet, and into essentially only one
- method in that servlet. Hence, if your page contains many, many tags, that
- method becomes too big, and up comes the exception that you're seeing.
主要原因是JAVA文件中对方法有一个大小限制,最大不超过64K,而我的JSP中编译成SERVLET代码的时候就变成了service方法,
这个方法的大小不能超过64K,当JSP文件太大的时候编译成的serviece方法自然就超过了,所以会提供
code too large
for
try
statement,解决方法有:
- There are a couple of (partial) solutions.
- 1) Break your giant page up into multiple smaller pages and bring them
- together at run time using <jsp:include>. Note that <%@include> won't work,
- because that's a compile-time include, which will get you straight back to
- the original problem.
- 2) Look for places to save on tags. For example, the <html:option> tag was
- recently extended to allow the specification of the text to display, so
- that you can replace this:
- <html:option ... ><bean:message key="foo"/></html:option>
- with this:
- <html:option ... key="foo"/>
主要有两个解决方法:一个是拆分成多个JSP文件,使用JSP:INCLUDE命令而不是使用<%@INCLUDE%>命令。
第二个是针对使用JSTL或自定义标签的情况,尽量使用产生代码少一些的标签。
在帖子:http://www.javaeye.com/post/57265
提到WEBLOG解决了这个问题:
- weblogic 9 解决了这个问题,发布在他上面就不会有任何问题了。我试过了。这个问题也困扰了我们项目组很久。
这个我没有试过。