this is the code of my jsp page.
<div id="showscriptonpage" style="display:none" >
<%@ include file="gdScripOnHome.jsp" %>
<%@ include file="gdScriptOffHome.jsp" %>
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.
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 ]
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.
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 ]
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.
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.
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.
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.
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.