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

相关链接:
http://topic.csdn.net/t/20041111/20/3544983.html
http://www.iteye.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. <tdwidth=""CLASS="fmkey"valign="top">BuCode:</td>
  3. <tdwidth=""class="fmvalue"align="left">
  4. <INPUTTYPE="TEXT"NAME="BuCode"SIZE="23"CLASS="<%=sStyle%>">
  5. </span>
  6. </td>
  7. <td>
  8. <INPUTTYPE="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. </tr>
具体问题如下:

  1. <<2008-12-1110:19:57.750>>(HttpUtil)ErrorMsg:callpage
  2. ExceptionMsg:org.apache.jasper.JasperException:UnabletocompileclassforJSP
  3. Anerroroccurredatline:-1inthejspfile:null
  4. Generatedservleterror:
  5. [javac]Compiling1sourcefile
  6. C:\DOCUME~1\WEIFEN~1\LOCALS~1\Temp\Jetty_0_0_0_0_8080__GeTSmart\Tdec_jsp.java:147:codetoolargefortrystatement
  7. try{
  8. ^
  9. 1error
  10. atorg.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
  11. atorg.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
  12. atorg.apache.jasper.compiler.Compiler.generateClass(Compiler.java:340)
  13. atorg.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
  14. atorg.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
  15. atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
  16. atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
  17. atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
  18. atjavax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  19. atorg.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  20. atorg.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  21. atorg.mortbay.jetty.servlet.Dispatcher.dispatch(Dispatcher.java:192)
  22. atorg.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:129)
  23. atcom.gobusiness.eus.util.HttpUtil.callPage(HttpUtil.java:225)
  24. atcom.gobusiness.eus.servlet.CreateDocServlet.doPost(CreateDocServlet.java:365)
  25. atcom.gobusiness.eus.servlet.CreateDocServlet.doGet(CreateDocServlet.java:76)
  26. atjavax.servlet.http.HttpServlet.service(HttpServlet.java:740)
  27. atjavax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  28. atorg.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  29. atorg.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  30. atorg.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
  31. atorg.mortbay.http.HttpContext.handle(HttpContext.java:1714)
  32. atorg.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
  33. atorg.mortbay.http.HttpContext.handle(HttpContext.java:1664)
  34. atorg.mortbay.http.HttpServer.service(HttpServer.java:863)
  35. atorg.jboss.jetty.Jetty.service(Jetty.java:460)
  36. atorg.mortbay.http.HttpConnection.service(HttpConnection.java:775)
  37. atorg.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
  38. atorg.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
  39. atorg.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
  40. atorg.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
  41. atorg.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
也有出现这个问题: (Codeofamethodlongerthan65535bytes)
  1. ExceptionMsg:javax.servlet.ServletException:org/apache/jsp/Tdec_jsp(Codeofamethodlongerthan65535bytes)
  2. atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
  3. atjavax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  4. atorg.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  5. atorg.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  6. atorg.mortbay.jetty.servlet.Dispatcher.dispatch(Dispatcher.java:192)
  7. atorg.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:129)
  8. atcom.gobusiness.eus.util.HttpUtil.callPage(HttpUtil.java:225)
  9. atcom.gobusiness.eus.servlet.CreateDocServlet.doPost(CreateDocServlet.java:365)
  10. atcom.gobusiness.eus.servlet.CreateDocServlet.doGet(CreateDocServlet.java:76)
  11. atjavax.servlet.http.HttpServlet.service(HttpServlet.java:740)
  12. atjavax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  13. atorg.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
  14. atorg.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
  15. atorg.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
  16. atorg.mortbay.http.HttpContext.handle(HttpContext.java:1714)
  17. atorg.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
  18. atorg.mortbay.http.HttpContext.handle(HttpContext.java:1664)
  19. atorg.mortbay.http.HttpServer.service(HttpServer.java:863)
  20. atorg.jboss.jetty.Jetty.service(Jetty.java:460)
  21. atorg.mortbay.http.HttpConnection.service(HttpConnection.java:775)
  22. atorg.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
  23. atorg.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
  24. atorg.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
  25. atorg.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
  26. atorg.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)

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

  1. Theproblemisthatthereisalimitonthesizeofacompiledmethodina
  2. Javaclassfile,andthatlimitiswhatwe'rerunningupagainst.Recall
  3. thataJSPpageiscompiledintoaservlet,andintoessentiallyonlyone
  4. methodinthatservlet.Hence,ifyourpagecontainsmany,manytags,that
  5. methodbecomestoobig,andupcomestheexceptionthatyou'reseeing.

主要原因是JAVA文件中对方法有一个大小限制,最大不超过64K,而我的JSP中编译成SERVLET代码的时候就变成了service方法,
这个方法的大小不能超过64K,当JSP文件太大的时候编译成的serviece方法自然就超过了,所以会提供 codetoolarge for try statement,解决方法有:

  1. Thereareacoupleof(partial)solutions.
  2. 1)Breakyourgiantpageupintomultiplesmallerpagesandbringthem
  3. togetheratruntimeusing<jsp:include>.Notethat<%@include>won'twork,
  4. becausethat'sacompile-timeinclude,whichwillgetyoustraightbackto
  5. theoriginalproblem.
  6. 2)Lookforplacestosaveontags.Forexample,the<html:option>tagwas
  7. recentlyextendedtoallowthespecificationofthetexttodisplay,so
  8. thatyoucanreplacethis:
  9. <html:option...><bean:messagekey="foo"/></html:option>
  10. withthis:
  11. <html:option...key="foo"/>

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

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

你可能感兴趣的:(java,apache,jsp,servlet,360)