36

So I'm dealing with a legacy servlet code that runs on Websphere 7 (JDK 6). Development environment setup uses Tomcat 6 (JDK 6).

  1. Why does it work on Websphere 7 and not in Tomcat 6?
  2. Is this something related to the application server?

If your answer is yes for no. 2, do you have a workaround for this on Tomcat 6 (JDK 6) aside from breaking down the code or using dynamic includes?

The schedule does not agree with changing static includes to dynamic includes primarily because most pages are coupled with the business model code including the main template of the app.

setzamora
  • 3,560
  • 6
  • 34
  • 48

11 Answers11

24

I ran out of static html/jss/css blocks I could externalize into jsp:include (mostly non-static html was left) ...

You can put in your web.xml, mappedfile set to false like so to get rid of many static lines that aren't necessarily good blocks to put into an include, but they add up to save space:

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    ...
    <init-param>
        <param-name>mappedfile</param-name>
        <param-value>false</param-value>
    </init-param>
    ...
</servlet>

Peter Hart's <c:catch> solution sounds like nice option as well.

rlegendi
  • 10,466
  • 3
  • 38
  • 50
armyofda12mnkeys
  • 3,214
  • 2
  • 32
  • 39
23

It sounds like you're hitting a 64k method limit, probably due to how Tomcat builds a class out of your JSP. This page suggests changing your static includes like this:

<%@ include file="test.jsp" %>

To dynamic includes like this to avoid the issue:

<jsp:include page="test.jsp" /> 
WhiteFang34
  • 70,765
  • 18
  • 106
  • 111
  • yes, I am aware of this, I have rephrased my last question that's what I meant - dynamic includes – setzamora Mar 30 '11 at 09:37
  • Ah. I doubt you have much option with Tomcat then, unless you want to hack it to break apart long methods to avoid the limitation. There's no guarantee on how the web container breaks apart your JSP into Java to be compiled into a class. You'll need to find a container that happens to it differently than Tomcat, perhaps try Jetty or Resin? – WhiteFang34 Mar 30 '11 at 09:44
  • same thing for me. Thanks! – migueloop Feb 13 '15 at 09:59
  • Good one but if I do include with jsp:include then – Srikanth Jul 17 '18 at 12:50
  • Understood now, taglib was in parent page that's why – Srikanth Jul 17 '18 at 13:04
14

Better to point direct where to change it as stated in following link: https://www.assetbank.co.uk/support/documentation/knowledge-base/byte-limit-exceeded-error/

Locate the file [Tomcat_Home]/conf/web.xml and search the file for 'JspServlet'. This should return an xml node of <servlet> containing some <init-param> values. You will need to add an additional <init-param> the same as the below.

<init-param>
    <param-name>mappedfile</param-name>
    <param-value>false</param-value>
</init-param> 

That's more clear and direct for tomcat user

Other reference solutions that of course, mostly said in previous comment but all in one place to read, here: http://answered.site/development-environment-setup-uses-tomcat-6-jdk-6-why-does-it-work/603017/

The issue also found in tomcat-8 with JDK1.8 (Java8)

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Osify
  • 2,253
  • 25
  • 42
  • ...but the answered.site link does not. – FreeText Jan 16 '19 at 17:46
  • 1
    Yes, other site is not working but still can see in https://support.assetbank.co.uk/hc/en-gb/articles/115005208888-How-do-I-fix-a-65535-bytes-limit-Stacktrace- – Osify Jan 17 '19 at 08:10
  • thanks for this hint and the links. it helps a little bit - unfortunately in my case only 2% less size of the generated Java/class files. – leole Nov 28 '19 at 10:30
4

For JBoss eap 6 in standalone.xml add the below code under web subsytem.

<configuration>
    <jsp-configuration development="true" mapped-file="false"/>
</configuration>

It resolved my issue.

4

Sometimes breaking your JSP into includes doesn't make sense or doesn't work. Another way to force your JSP to be broken into separate methods when compiled is to separate your JSP into segments using <c:catch>.

Peter J. Hart
  • 367
  • 2
  • 7
  • Would you mind to elaborate how to force more segements via the usage of ? I couldn't find any other sources concerning this 'hack', which i could use right now very much! Thanks for your trouble! – Benjamin Seiller Apr 13 '12 at 15:43
  • Never mind - found a "cleaner" solution (jsp:include), being able to read sometimes helps a lot :) – Benjamin Seiller Apr 17 '12 at 12:47
  • 1
    To use includes, you have to create more files. This is usually fine. But when it isn't, divide the code in the page into blocks wrapped with . This forces the resulting servlet to break the page into multiple methods. – Peter J. Hart May 31 '13 at 20:31
3

Why does it work on Websphere 7 and not in Tomcat 6

Because they have different JSP compilers that translate the JSPs to different Java code. The Tomcat JSP compiler (Jasper) is apparently not able to deal with large JSPs.

Perhaps the next question is, is it possible to change the method size limit of the JVM?

No. These limits are hard-wired into the format / structure of class files.

The details are in the JVM spec ... but it is rather complicated, and it is not entirely clear from your question which limit you have hit. (But that is immaterial ... they can't be changed.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • It's actually not that simple. The method_count field limits the number of methods per class, not the code length for each method. The relevant field, code_length in the Code_attribute struct, is a 32 bit unsigned integer, but since other attributes are indexing the code using 16 bit unsigned integers, it is additionally stated in the class file format specification that "the value of the code_length item must be less than 65536". In some cases, it must even be less than 65535, since an instruction on index 65535 cannot be protected by an exception handler. – jarnbjo Mar 30 '11 at 12:03
  • the hit error is regarding the method name "_jspService" which is what the jsp code turns into. The compiler is not smart enough to split a long code into multiple (chained) "_jspServiceXXX" methods. The bytecode of a method may not be longer than 65535bytes. Some other tools also fail to generate proper code. 'asm for instance fails at generating "bytecode" of large classes and the error is just the same. – bestsss Mar 30 '11 at 13:28
2

By setting initialization parameter "mappedFile" to "false" worked for me.

But using eclipse plugin some time it is getting removed and need to again set in tomcat home.

Chaitu
  • 61
  • 5
2

I stumbled across this issue today
My problem was solved as I took Tomcat 8.0.30 instead of Tomcat 8.0.39

Shinigami
  • 646
  • 1
  • 7
  • 21
  • 1
    Amazing, but this really helped in my case (had to get an old project running in order to bugfix something). I initially used apache-tomcat-7.0.78 with which I got the above exception. Then I tried with apache-tomcat-8.0.46, but still got the exception. Finally I tried apache-tomcat-8.0.30 from Apache's archive and it really worked. I would not rely on this for production, but to quickly get a bugfix session running. Perfect. Thanks. – stefitz Sep 27 '17 at 17:10
2

If you are going to fix this error _jspService is exceeding the 65535 bytes limit on Spring Boot with embedded tomcat you can use this config in your application.properties:

server.servlet.jsp.init-parameters.mappedfile=false
Maksym
  • 2,650
  • 3
  • 32
  • 50
1

Eidt: Given solution was no solution, but missinterpreation (problem can not be reproduced on all tomcat versions) sorry.

Frank
  • 11
  • 2
0

For wildfly server, In standalone.xml -> inside undertow subsystem : replace jsp-config with

<jsp-config development="true" mapped-file="false"/>
Community
  • 1
  • 1