编译JSP时出的问题:code too large for try statement

来源:互联网 发布:sql数据库恢复工具 编辑:程序博客网 时间:2024/05/16 10:16
相关链接:
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>,就出问题了,代码如下:注释的部分是我加的,加了后就出问题:

  1. <tr>
  2.         <td width="" CLASS="fmkey" valign="top">BuCode:</td>
  3.         <td width="" class="fmvalue" align="left">
  4.                 <INPUT TYPE="TEXT" NAME="BuCode" SIZE="23"  CLASS="<%=sStyle%>" >
  5.                 </span>
  6.         </td>
  7.         <td>
  8.         <INPUT TYPE="BUTTON" NAME="" VALUE=". . ."  CLASS="btnLook" onClick="openLookupGen(arrSetBuCode, arrGetBuCode ,'<%=EusUtil.getPage("lookup.generic.bucode.s")%>', arrBuCodeParam, 640, 480, 'yes')">
  9.         sfsfsf
  10.         </td>
  11.         <!-- <td>kkkee</td>  -->
  12.         
  13.         
  14.     </tr>
具体问题如下:

  1. <<2008-12-11 10:19:57.750>> (HttpUtil) ErrorMsg : callpage
  2. ExceptionMsg: org.apache.jasper.JasperException: Unable to compile class for JSP
  3. An error occurred at line: -1 in the jsp file: null
  4. Generated servlet error:
  5.     [javac] Compiling 1 source file
  6. 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
  7.     try {
  8.         ^
  9. 1 error
  10.     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
  11.     at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
  12.     at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:340)
  13.     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
  14.     at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
  15.     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
  16.     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
  17.     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
  18.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  19.     at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  20.     at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  21.     at org.mortbay.jetty.servlet.Dispatcher.dispatch(Dispatcher.java:192)
  22.     at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:129)
  23.     at com.gobusiness.eus.util.HttpUtil.callPage(HttpUtil.java:225)
  24.     at com.gobusiness.eus.servlet.CreateDocServlet.doPost(CreateDocServlet.java:365)
  25.     at com.gobusiness.eus.servlet.CreateDocServlet.doGet(CreateDocServlet.java:76)
  26.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
  27.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  28.     at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  29.     at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  30.     at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
  31.     at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
  32.     at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
  33.     at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
  34.     at org.mortbay.http.HttpServer.service(HttpServer.java:863)
  35.     at org.jboss.jetty.Jetty.service(Jetty.java:460)
  36.     at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)
  37.     at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
  38.     at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
  39.     at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
  40.     at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
  41.     at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
也有出现这个问题:(Code of a method longer than 65535 bytes)
  1. ExceptionMsg: javax.servlet.ServletException: org/apache/jsp/Tdec_jsp (Code of a method longer than 65535 bytes)
  2.     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
  3.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  4.     at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  5.     at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  6.     at org.mortbay.jetty.servlet.Dispatcher.dispatch(Dispatcher.java:192)
  7.     at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:129)
  8.     at com.gobusiness.eus.util.HttpUtil.callPage(HttpUtil.java:225)
  9.     at com.gobusiness.eus.servlet.CreateDocServlet.doPost(CreateDocServlet.java:365)
  10.     at com.gobusiness.eus.servlet.CreateDocServlet.doGet(CreateDocServlet.java:76)
  11.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
  12.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  13.     at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  14.     at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  15.     at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
  16.     at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
  17.     at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
  18.     at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
  19.     at org.mortbay.http.HttpServer.service(HttpServer.java:863)
  20.     at org.jboss.jetty.Jetty.service(Jetty.java:460)
  21.     at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)
  22.     at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
  23.     at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
  24.     at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
  25.     at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
  26.     at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)

查了相关的资料:
http://marc.info/?l=struts-user&m=98512887614286&w=2
这个帖子解释的比较清楚,还提供了相关的办法

  1. The problem is that there is a limit on the size of a compiled method in a 
  2. Java class file, and that limit is what we're running up against. Recall 
  3. that a JSP page is compiled into a servlet, and into essentially only one 
  4. method in that servlet. Hence, if your page contains many, many tags, that 
  5. 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,解决方法有:

  1. There are a couple of (partial) solutions.
  2. 1) Break your giant page up into multiple smaller pages and bring them 
  3. together at run time using <jsp:include>. Note that <%@include> won't work, 
  4. because that's a compile-time include, which will get you straight back to 
  5. the original problem.
  6. 2) Look for places to save on tags. For example, the <html:option> tag was 
  7. recently extended to allow the specification of the text to display, so 
  8. that you can replace this:
  9. <html:option ... ><bean:message key="foo"/></html:option>
  10. with this:
  11. <html:option ... key="foo"/>

主要有两个解决方法:一个是拆分成多个JSP文件,使用JSP:INCLUDE命令而不是使用<%@INCLUDE%>命令。
第二个是针对使用JSTL或自定义标签的情况,尽量使用产生代码少一些的标签。

在帖子:http://www.javaeye.com/post/57265
提到WEBLOG解决了这个问题:
  1. weblogic 9 解决了这个问题,发布在他上面就不会有任何问题了。我试过了。这个问题也困扰了我们项目组很久。 
这个我没有试过。
原创粉丝点击