6

Inside a jsp I have a small header :

<%@ page import="java.util.*"%>

<% HttpSession CurrentSession =
 request.getSession();
 ...
%>

...and a big 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?

AllTooSir
  • 48,828
  • 16
  • 130
  • 164
user2334908
  • 61
  • 1
  • 1
  • 2
  • Do you have any static includes in your JSP ? – AllTooSir Apr 30 '13 at 07:32
  • This illustrates an important point for language/runtime designers; consider that programs in your language may be *computer generated* (perhaps if your language is used as a target for compilation). Limits which will never be hit by hand-written programs can easily cause problems for computer-generated programs. – Alex D Apr 30 '13 at 07:48
  • @Alex but computer scripts can also be programmed to automatically split the method up. – Antimony Apr 30 '13 at 11:50

3 Answers3

2

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.

If possible change static includes (really embedding an other JSP source) with dynamic includes.

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>:

<%@

    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.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
2

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").

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.

Community
  • 1
  • 1
eis
  • 51,991
  • 13
  • 150
  • 199
0

The <jsp:include page="foo.html" %> standard action can be used to include content at runtime - see some random documentation.

McDowell
  • 107,573
  • 31
  • 204
  • 267