_jspService is exceeding the 65535 bytes limit
Asked Answered
A

11

37

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.

Affra answered 30/3, 2011 at 9:4 Comment(5)
Downloading WAS 6 express now.Affra
Perhaps the next question is, is it possible to change the method size limit of the JVM?Affra
I'd refactor (large) parts to (include) tags. The (flawed) business model is a non-argument.Klaraklarika
Answer to the "next question" is. No. Plain and simple. The limit is in the class file format ... not the JVM.Waldheim
also see this #7496485Bdellium
I
25

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.

Inadequate answered 29/6, 2011 at 17:36 Comment(1)
Thanks, this solution helped me a lot and saved my time.Forenamed
T
24

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" /> 
Tumbling answered 30/3, 2011 at 9:30 Comment(4)
yes, I am aware of this, I have rephrased my last question that's what I meant - dynamic includesAffra
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?Tumbling
Good one but if I do include with jsp:include then <form: this tag not working for me. help me if any alternativeInchon
Understood now, taglib was in parent page that's why <form: tag not working. now i added taglib in child page, working fine. thank youInchon
C
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)

Crux answered 30/11, 2015 at 10:26 Comment(3)
...but the answered.site link does not.Inwrap
Yes, other site is not working but still can see in support.assetbank.co.uk/hc/en-gb/articles/…Crux
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.Jagir
S
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>.

Swiftlet answered 27/4, 2011 at 19:18 Comment(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!Psf
Never mind - found a "cleaner" solution (jsp:include), being able to read sometimes helps a lot :)Psf
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.Swiftlet
M
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.

Mcwhorter answered 26/5, 2015 at 7:21 Comment(0)
W
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.)

Waldheim answered 30/3, 2011 at 9:57 Comment(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.Vieira
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.Towill
S
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.

Shaquitashara answered 28/5, 2014 at 6:19 Comment(0)
E
2

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

Ellynellynn answered 12/1, 2017 at 15:53 Comment(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.Tritanopia
N
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
Newfeld answered 16/9, 2020 at 16:32 Comment(0)
S
1

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

Stanwood answered 26/10, 2016 at 9:6 Comment(0)
S
0

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

<jsp-config development="true" mapped-file="false"/>
Stoplight answered 18/8, 2016 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.