0

I have a very huge json string that i'm trying to pass from one jsp to another through a hidden form method. But when i receive it in my other jsp only half the string appears, i do know it is very large. My results.jsp has different ids and on clicking any one of them it goes to details.jsp, which is passed both the id clicked and the whole string through a hidden form. I think POST method has a limit on the size passed and thus my whole string is not sent.

results.jsp

       <head>
            <script type="text/javascript">
                    function submitHiddenForm(Key) {

                   document.getElementById("Key").value = Key;
                   document.myForm.submit();

               }
                </script>
        </head>
    <body>

        <div class="list-group">
            <% 
                List<ComparisonResultDTOarr> ls = diff.getComparisonResultDTOarr();

                for(int i = 0;i<ls.size();i++)
                {
                List<AuditItemLogsDTOArr> lsinner = ls.get(i).getAuditItemLogsDTOArr();
                %><a href="#" onclick="submitHiddenForm('<%=lsinner.get(0).getKeyAsString()%>')" class="list-group-item"> 
                <%out.println(lsinner.get(0).getKeyAsString());%></a><%
                }
            %>
       </div>

        <form action="details.jsp" method="post" name="myForm">
         <input type="hidden" name="Key" id="Key"><br>
         <input type="hidden" name="jsonString" id="jsonString" value=<%=(String)request.getAttribute("jsonstring") %>>
        </form>
    </body>

and in my details.jsp i am simply getting the parameters

<%
String Key = request.getParameter("Key");
String jsonstr = (String)request.getParameter("jsonString");
%>

and displaying the jsonstr in a paragraph:

<p><%=jsonstr %></p>

but its incomplete and only displays partially. I know this is a bit confusing so please let me know if you need any more details.

P.S - I cannot use dispatcher as it needs to be onclick of the ID.

damien hawks
  • 512
  • 3
  • 17
  • possible duplicate of [Is there a max size for POST parameter content?](http://stackoverflow.com/questions/2943477/is-there-a-max-size-for-post-parameter-content) – Scary Wombat Jul 01 '14 at 07:10
  • I know there is a max size. that is why my content is being cut, i want to know what other method up to do this @ScaryWombat also im using weblogic not tomcat – damien hawks Jul 01 '14 at 07:11

2 Answers2

1
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<input
    type="hidden" name="jsonString" id="jsonString"
    value="<c:out value="${jsonstring}">">

Of course the HTML attribute value need quotes, and the JSP tag <c:out> escapes what is to escape, like " inside the string. ` would suppress the escaping.

${jsonString} is EL, expression language, which can be used throughout, simplifying everything.

For a really large string I would suggest an other data flow. Maybe Ajax with JavaScript, but it seems that you would need to modify the prior JSP to just past query params or so.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • I know about EL but my project is more legacy and i have been asked to use scriplets though it isn't best practice. And thank you can you direct me to some resources i could use? Also i need this string across all my jsp pages so would you recommend setting it in my session variable or would that be the wrong approach? – damien hawks Jul 01 '14 at 07:20
  • 2
    If the json is personalized/individual it could be kept there, maybe compressed when huge. Can it really not be an URL to a servlet that either dynamically creates it, or takes it from the session, or from a database? Not so fast but cleaner and maybe faster initial page loads. You could also do a forward (in a JSP scriptlet) to the servlet to embed the JSON text. – Joop Eggen Jul 01 '14 at 09:02
  • This answer didn't solve my problem completely but it sure did help so i've upvoted both your answer & comment! thanks! – damien hawks Jul 01 '14 at 09:41
0

Considering previous answer and comments of answer by Joop Eggen, what I think is problem may be as below:

  1. JSON data is unescaped
  2. Wrong choice of passing data to JSP page

First approach I am suggesting is because you have JSON String which is not escaped, and while displaying it as HTML may be its getting lost. In this case you need to be careful to escape it properly in context of JSP as well as HTML along with SCRIPT where you are passing it. I have faced this issue for my JSON data. I had choose to escape JSON data. Also I would suggest to print data multiple times in logs to confirm its present. If data is large confirm its length.

Second approach, Another way from your conversation I am getting is using session to store String data. If you have to use data multiple times keep it in session that way it would be easy to handle.

Your solution to answer would be combination of both approaches mentioned above. If you use them simultaneously you can do it easily.

user3657302
  • 347
  • 1
  • 5