Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

code limit of 65535 elements  RSS feed

 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

this is the code of my jsp page.

<div id="showscriptonpage" style="display:none" >
<%@ include file="gdScripOnHome.jsp" %>
</div>

<div id="showscriptoffpage">
<%@ include file="gdScriptOffHome.jsp" %>
</div>

I am getting the following error. Please help to solve it.

Semantic Error: Method "void _jspService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException;" in type "gdHome_xjsp" produced a code attribute that exceeds the code limit of 65535 elements.


thanks,
Neeraj
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the sizes of your two includes?

Remember, the include directive <%@ include ..%> merges the code before compiling. If the sum of your includes exceeds the limit for the JVM, you're going to have a problem.

Using the JSP include action <jsp:include ../> won't cause all the code to be merged. It will instead run each of the included pages separately at runtime and merge the output.

If I were hitting this limit, I would seriously consider refactoring my app.
JSPs of this size must be very difficult to maintain.
[ June 28, 2006: Message edited by: Ben Souther ]
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your inputs. it worked for me.

Both the jsp's have around 600 lines of code including the html forms.My application is based on struts.

We have a different application deployed on the same server with a different context.it has jsp files with more than 2000 lines of code.But it is not throwing the exception there.

In my case could it be because of struts ? it's just my guess.. since other environment settings are same.

Thanks,
Neeraj.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know enough about how Struts works to say.
Do the include pages themselves have include directives?
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it has include directives..
thanks,
Neeraj.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it's possible that the total size (sum of all includes) exceeds the limit (64k, I believe)?
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes.. it exceeds and executes without any error.

thanks,
Neeraj.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The message came from the Jikes compiler.

I agree with the comments above that this was likely caused by a JSP which resulted in a method that was too big.

Take a look at the _jspService() method in the servlet class generated from the JSPs. I'll bet it's several thousand lines which translates into more than 64k java bytecode instructions.

Do you have any scriptlets in the JSPs? Could they be generating large numbers of bytecodes? Can they be moved to separate methods, classes or tags?
[ July 01, 2006: Message edited by: Scott Johnson ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've run into this limit before in a Struts JSP. The Struts custom actions (tags) put a lot of code into the compiled jsp module. Furthermore, a fairly busy Struts JSP could end up using quite a few Struts custom actions. This can get you close to the maximum size quite easily.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Neeraj Vij:

Thanks for your inputs. it worked for me.


For the record, I would consider my suggestion (change from include directive to include action), as a test for diagnosing the problem or, maybe as a stop gap measure (stop the bleeding long enough to get the patient to the hospita) and not as a solution.

If your JSPs are generating that much servlet code, (especially in an MVC environment) it's time to schedule some development time for refactoring. It sounds like it will only be a matter of time before this problem pops up again.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am not using any scriplets in my jsp's. I am using jstl tags only.I am still not clear why, <jsp:include> is working . The major difference I know between <jsp:include> and <%@include > is that, <jsp:include> checks everytime whether the included jsp has changed or not. Please correct me if am wrong.

I am trying to figure out why the non-struts application deployed in a different context on the same server with moe than 2000 lines of code is working fine, while mine jsp's with around 1200 line are not working.

Thanks,
Neeraj.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could it be because of using jstl ?.. since files with more than 2000 lines have very minimal jstl.. and i have extensivly used jstl

Thanks
neeraj.
 
Neeraj Vij
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what points should be cosidered while refactoring my jsp ?

Thanks.
Neeraj.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The major difference I know between <jsp:include> and <%@include > is that, <jsp:include> checks everytime whether the included jsp has changed or not.



The difference is that with <% @include %> the include occurs at translation time (when the JSP is translated into a servlet) so the content becomes part of the _jspService() method.

On the other hand, <jsp:include> causes the include to occur at runtime.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could it be because of using jstl?


Take a look at the _jspService() method of the JSP's servlet. (The JSP gets translated into a servlet and compiled). You should be able to tell where the thousands of lines of code are coming from.
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what points should be cosidered while refactoring my jsp ?


JavaWorld has an article on JSP best practices.

Some of the rules we've defined for my current project are:

1. No scriptlets in JSPs. (Use taglibs and EL as necessary.)
2. Use the MVC Model 2 pattern. All business logic goes in a EJB. All controller code goes in a Struts Action.
3. Use templates and includes to avoid duplicating HTML (headers and footer, for example) and to break up HTML into small, logical units.
4. All HTML must be compliant with HTML 4.01 Strict.
5. Use CSS for presentation/formatting.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a good list to follow, even if not using EJB and Struts.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!