Question

a little back story:

I am working on a file that got to be very large, eventually resulting in the following error:

The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit.

In order to get around this, I have been "modularising" the file by utilizing the jsp:include tags. I have successfully passed objects from the main file to the included file by serializing the objects and using the jsp:param tag and then deserializing in the jsp:include file. However, being as though these objects are used, modified and reused and re-modified in the main file and in multiple included files. I am wondering if there is a way to pass back the object to the main file after rendering the included file OR if there is a way to access these objects by reference so that they can be modified within one included file and the right instance of the modified object could be reused other included files below it?

So far I have considered pagecontext.setAttribute() (which does not seem to be by ref and does not seem to let me pass the value back after being modified to the main file) and jsp:param (pretty much the same thing as as the pagecontext.setAttribute()).

This is what I have so far:

Code Sample below: (I hope this doesn't confuse anyone. I'm not looking for syntax corrections, I'm just looking for a solution that will allow the same object to be accessed by reference (such as a global variable along with the include tags) or for me to pass the object back to the main.jsp so that the next jsp:include can access it after it's been modified.

Main.jsp

    //Serialized Objects, Google Gson object
       Gson gson = new Gson();

       String serializedObject = gson.toJson( objectName );


    <jsp:include page="/includes/includedFileName1.jsp">
       <jsp:param name="serializedObject" value="<%= serializedObject %>" />
    </jsp:include>

   <!-- Is there a way to ensure includedFileName2 .jsp gets the modified version of object from includedFileName1.jsp? -->

    <jsp:include page="/includes/includedFileName2.jsp">
       <jsp:param name="serializedObject" value="<%= serializedObject %>" />
    </jsp:include>

   <!-- Is there a way to ensure includedFileName3 .jsp gets the modified version of object from includedFileName2.jsp? -->

    <jsp:include page="/includes/includedFileName3.jsp">
       <jsp:param name="serializedObject" value="<%= serializedObject %>" />
    </jsp:include>

includedFileName1.jsp

    //Gson object used to convert serialized strings to java objects
    Gson gson = new Gson();

    ObjectType object = null;
    if (null != request.getParameter("serializedObject")) {
       object = gson.fromJson(request.getParameter("serializedObject"), ObjectType.class);
    }

    if (x = y) {object = somethingNew1;}

//is there a way to pass object back to the main.jsp?

includedFileName2.jsp

//Gson object used to convert serialized strings to java objects
Gson gson = new Gson();

ObjectType object = null;
if (null != request.getParameter("serializedObject")) {
   object = gson.fromJson(request.getParameter("serializedObject"), ObjectType.class);
}

if (x = y) {object = somethingNew2;}

//is there a way to pass object back to the main.jsp?

includedFileName3.jsp

//Gson object used to convert serialized strings to java objects
Gson gson = new Gson();

ObjectType object = null;
if (null != request.getParameter("serializedObject")) {
   object = gson.fromJson(request.getParameter("serializedObject"), ObjectType.class);
}

if (x = y) {object = somethingNew3;}

//is there a way to pass object back to the main.jsp?

The object may or may not be modified but has to be accessible from all three includes and the objects latest changes has to be accesible.

Thank you for your time.

Was it helpful?

Solution

Thanks @home, @Ashley ...

I re-thought the way this was implemented and resolved my issue using request.setAttribute() and request.getAttribute().

<% 
    //set new parameters to be passed through to the jsp:include
    request.setAttribute("objectName", objectInstance);
%>
    <jsp:include page="/includes/requisitionClinicalConditionContent.jsp"/>
<%
    //get parameters passed from the jsp:include
    objectInstance = (object) request.getAttribute("objectName");
%> 

I pass through the object using request.setAttribute() and receive it in my jsp:include. If it was modified within the jsp:include (which it isn;t in most cases, but I do have 1 or two cases which may modify the value), I return the object from the jsp:iclude using request.setAttribute(0 and recive it back in my parent jsp page.

Thanks for all the help, I'm sorry I didn't reply back sooner.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top