I am, unfortunately, intimately familiar with this problem.

The problem is that there is a limit on the size of a compiled method in a 
Java class file, and that limit is what we're running up against. Recall 
that a JSP page is compiled into a servlet, and into essentially only one 
method in that servlet. Hence, if your page contains many, many tags, that 
method becomes too big, and up comes the exception that you're seeing.

There are a couple of (partial) solutions.

1) Break your giant page up into multiple smaller pages and bring them 
together at run time using <jsp:include>. Note that <%@include> won't work, 
because that's a compile-time include, which will get you straight back to 
the original problem.

2) Look for places to save on tags. For example, the <html:option> tag was 
recently extended to allow the specification of the text to display, so 
that you can replace this:

<html:option ... ><bean:message key="foo"/></html:option>

with this:

<html:option ... key="foo"/>

If you have a lot of cases of this pattern, it can help quite a bit. In 
addition to the <html:option> tag, some other Struts tags allow the same 
shortcut to including the text. Also, you might consider replacing 
<html:option> sequences with <html:options> if you can build an appropriate 
collection up front.

Unfortunately, we can't use solution (1), because our giant page is almost 
entirely one <html:form>. (Please don't ask... :-} ) Many of the <html:*> 
tags won't work if they are on a separate page from the <html:form> tag 
itself. That means I've spent quite some time on option (2).

We have several of our own tags, too, so that was the next place for me to 
look. I discovered that changing some frequently used tags from extending 
BodyTagSupport to extending TagSupport, and marking them with 
<bodycontent>empty</bodycontent> in the .tld file, made a significant 
reduction in generated code size. Of course, this is not always feasible, 
but it helped us quite a bit.

One other trick is to create custom tags for frequently used groups of 
related elements. For example, I created a simple DatePickerTag which is a 
Struts-like tag that combines three drop-down boxes for month, day and 
year, with the localized strings obtained from the JVM, and the current 
values pulled from a bean.

That's about all I can think of that I've tried so far. All our pages are 
now within the limit, but one is very close to breaking it. I really want 
to put a "do not touch" notice on that file!

Hope this helps.

--
Martin Cooper


At 12:06 PM 3/20/01, Marc Ellison wrote:
>Hi,
>
>I have been getting a very interesting error folks ;-)
>
>I have constructed a jsp file that uses ALOT of struts-defined tags, and
>which I have running with Tomcat.  Initially the page would not work so I
>commented out a lot of the code.  The page now works to an extent, but as
>soon as I try to uncomment any of the other struts tags it throws this error
>message.....
>
>javax.servlet.ServletException: (class:
>_0002fdemographicDetails_0002ejspdemographicDetails_jsp_73, method:
>_jspService signature:
>(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletRespo
>nse;)V)
>
>I have looked in the mail archive and one guy suggested changing the values
>of the stack/memory allocation pools to a higher value as it couldn't cope
>with the number of tags.  However, I still get the same error. Has anybody
>encountered a similar problem....if so please HELP!!
>Kind regards
>Marc


Reply via email to