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.

5
  • Downloading WAS 6 express now.
    – setzamora
    Mar 30, 2011 at 9:51
  • Perhaps the next question is, is it possible to change the method size limit of the JVM?
    – setzamora
    Mar 30, 2011 at 9:54
  • 1
    I'd refactor (large) parts to (include) tags. The (flawed) business model is a non-argument.
    – BalusC
    Mar 30, 2011 at 12:51
  • Answer to the "next question" is. No. Plain and simple. The limit is in the class file format ... not the JVM.
    – Stephen C
    May 23, 2013 at 8:04
  • also see this stackoverflow.com/questions/7495985/…
    – NoNaMe
    Oct 30, 2014 at 7:13

11 Answers 11

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.

1
  • Thanks, this solution helped me a lot and saved my time.
    – mahi
    Jun 30, 2017 at 13:09
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" /> 
5
  • yes, I am aware of this, I have rephrased my last question that's what I meant - dynamic includes
    – setzamora
    Mar 30, 2011 at 9: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? Mar 30, 2011 at 9:44
  • same thing for me. Thanks!
    – migueloop
    Feb 13, 2015 at 9:59
  • Good one but if I do include with jsp:include then <form: this tag not working for me. help me if any alternative
    – Srikanth
    Jul 17, 2018 at 12:50
  • Understood now, taglib was in parent page that's why <form: tag not working. now i added taglib in child page, working fine. thank you
    – Srikanth
    Jul 17, 2018 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)

3
  • ...but the answered.site link does not.
    – FreeText
    Jan 16, 2019 at 17:46
  • 1
    Yes, other site is not working but still can see in support.assetbank.co.uk/hc/en-gb/articles/…
    – Osify
    Jan 17, 2019 at 8: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, 2019 at 10:30
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>.

3
  • Would you mind to elaborate how to force more segements via the usage of <c:catch>? I couldn't find any other sources concerning this 'hack', which i could use right now very much! Thanks for your trouble! Apr 13, 2012 at 15:43
  • Never mind - found a "cleaner" solution (jsp:include), being able to read sometimes helps a lot :) Apr 17, 2012 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 <c:catch>. This forces the resulting servlet to break the page into multiple methods. May 31, 2013 at 20:31
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.

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

2
  • 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, 2011 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, 2011 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.

2

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

1
  • 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, 2017 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
1

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

0

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.