java 方法的代码...超出了 65535 字节的限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16294505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The code of method ... is exceeding the 65535 bytes limit
提问by user2334908
Inside a jsp I have a small header :
在jsp里面我有一个小标题:
<%@ page import="java.util.*"%>
<% HttpSession CurrentSession =
request.getSession();
...
%>
...and a big html
...和一个大 html
<html>
...
</html>
If I try to read it as is I get an error of "...is exceeding the 65535 bytes limit".I have to break it up.Since I am new to java I cannot figure it out how to do it.Could you please indicate me the way?
如果我尝试按原样阅读它,我会收到“...超出 65535 字节限制”的错误。我必须将其分解。由于我是 Java 新手,我不知道该怎么做。你能吗请指点我的路?
回答by Joop Eggen
The JSP is converted into a normal Servlet java source, and some generated method is too large, as there is a 64 KB limit (on the byte code) on method lengths.
JSP转成普通的Servlet java源码,生成的一些方法过大,方法长度有64KB(字节码)限制。
If possible change static includes (really embedding an other JSP source) with dynamic includes.
如果可能,将静态包含(真正嵌入其他 JSP 源)更改为动态包含。
The solution (and probably good style) is too introduce a couple of methods into which pieces of the general code is moved. For instance to generate a HTML table row with <tr>
:
解决方案(也可能是好的风格)也引入了一些方法,将通用代码的片段移入其中。例如,生成一个 HTML 表格行<tr>
:
<%@
void tableRow(String... cellValues) {
%><tr><%
for (String cellValue : cellValues) {
%> <td><%= cellValue %></td>
<%
}
%></tr>
<%
}
%>
...
...
<%
tableRow("one", "unu", "un");
tableRow("two", "du", "deux");
tableRow("three", "tri", "trois");
%>
P.S.
The above method is too small scale to save much, taking a large piece and create a method
like createResultsTable
is more effective.
PS 上面的方法规模太小节省不了多少,拿大块创建一个like的方法createResultsTable
更有效。
回答by eis
JSPs get compiled into servlet code, which are then compiled into actual java .class files. JSP code will be put into one big doGet() method, and if your JSP file is really big, it will hit the method size limit of 65535. The limit is coming from JVM specification("The value of the code_length item must be less than 65536").
JSP 被编译成 servlet 代码,然后被编译成实际的 java .class 文件。JSP 代码会被放到一个大的 doGet() 方法中,如果你的 JSP 文件真的很大,它会达到方法大小限制 65535。这个限制来自JVM 规范(“code_length 项的值必须小于比 65536")。
You should split the file into several files. I wouldn't split it into different methods as proposed in this thread, since it can make the code logic even more complex in this case, but do a jsp:include for the HTML part(s) like proposed by McDowell.
您应该将文件拆分为多个文件。我不会像这个线程中提出的那样将它拆分成不同的方法,因为在这种情况下它可以使代码逻辑更加复杂,但是像McDowell 提出的那样为 HTML 部分执行 jsp:include 。
回答by McDowell
The <jsp:include page="foo.html" %>
standard action can be used to include content at runtime - see some random documentation.
该<jsp:include page="foo.html" %>
标准动作可用于包括在运行时的内容-看到一些随机文档。