request.getParameter - max size limit?

When the user enters a really long string (around 100 lines of text) into a textbox and in the following page, when I call request.getParameter("input"), I am getting a null pointer exception.

I tried to print request.getParameter this way
logger.severe(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>REQPARAM is" +request.getParameter("input"));

It prints the first 90 or so lines and then stops printing.

Does request.getParameter have any limit on max size and what are my options?

mytiligAsked:
Who is Participating?
 
TimYatesCommented:
>> I have simulated it using a simpler version of the code

And that crashes?

How about this:

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
  </head>
  <body>
    <form method="post">
      <label>ip
        <textarea name="ip" cols="55" rows="15"></textarea>
      </label>
      <p>
        <input type="submit" name="Submit" value="Submit" />
      </p>
    </form>
    <%= request.getParameter( "ip" ) %>
  </body>
</html>

That works for me...
0
 
rrzCommented:
Did you try changing your form method from "get"  to "post"  ?
0
 
mytiligAuthor Commented:
It is already POST
Also I just added  buffer="128kb" in my page tag. same error still.
Note that there is no error for smaller texts(smaller than 90 lines)

Thanks.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
jessegivyDeveloperCommented:
are you using input type="text" or a textarea?
0
 
mytiligAuthor Commented:
textarea
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
I don't think request.getParameter() has any limit especially in POST method.

can you put forward the JSP textarea code

it must be some thing like.

<input type="textArea" name="input" ...../>

am i correct ?

please just check if you have specified the name correctly.
0
 
mytiligAuthor Commented:
Here is the textarea tag in my initial jsp page.  
<textarea name="input" cols="55" rows="15"><%=emp.getDevTxt()%></textarea>

The text area will have default value from database.  

Everything works correctly for < 7399 characters (around 90 lines)
Above this size, I get the null pointer exception.

I have increased jsp buffer to 128kb like this buffer="128kb"
no luck still....
0
 
rrzCommented:
>I have increased jsp buffer to 128kb like this buffer="128kb"
I don't think that is the problem. I am guessing  you might be hitting one of these.
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#88659 
What does just  <%=emp.getDevTxt()%>   output  ?  
0
 
mytiligAuthor Commented:
Additional note:

I printed request.getContentLength(), found that my application works correctly until request.getContentLength()<= 7633 bytes.
If I add another character into my text area, request.getContentLength() becomes 7634 bytes and my app crashes....


<%=emp.getDevTxt()%> does print all my text intact. It is only when I pass it as a variable and retrieve it using request.getParameter that I have the issue.
Thank you.

0
 
jessegivyDeveloperCommented:
Hi, I'm perplexed.

I have to agree with shivaspk and take it a step further by saying that errors are rarely what they seem to be.  Let's see some code if you really need an answer.  Where you're having a problem is right at the request/response model so ensure that all surrounding code is completely in tact and you should be fine.

...really stumped on this one.  I'd love to see some code here!
0
 
mytiligAuthor Commented:
Here is the code snippet from my main JSP page

<script type="text/JavaScript">
function draft_btn()
{
      alert("Saving data ");
      document.empForm.action = "EmployeeDraft.jsp";
      document.empForm.submit();                  // Submit the page
      return true;
}
</script>

<form name="empForm" method="post" > 
<table> <tr><td>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="209" valign="top"><img src="../images/Values.jpg" width="180" height="277" /></td>
                    <td width="5" valign="top">&nbsp;</td>
                    <td align="left" valign="top"><span class="style9"><strong>Development Text : <br>(List a minimum of three)   &nbsp; &nbsp;&nbsp;
</strong> </span>
                        <br />
                     
                        <textarea name="dev" cols="55" rows="15"><%=emp.getDevTxt()%></textarea>
                        <br /></td>
                  </tr>
              </table> </tr></td>

<tr>
                    <td><input name="draft" type="button" id="draft" value=" Save Draft " OnClick="return draft_btn();" />
                      </td> </tr> </table>
</form>
</body>
</html>

Here is the code snippet from 2nd jsp page

if (request.getParameter("dev") !=null ) {
logger.severe("Request size is " +request.getContentLength());
logger.severe(" MM..............    "+Runtime.getRuntime().maxMemory() + "free >>>> " +Runtime.getRuntime().freeMemory());
logger.severe(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>REQPARAM is" +request.getParameter("dev"));
}


0
 
mytiligAuthor Commented:
I have simulated it using a simpler version of the code

test1.jsp
---------------------

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="test2.jsp">
  <label>ip
  <textarea name="ip" id="ip"  cols="55" rows="15"></textarea>
  </label>
  <p>
    <input type="submit" name="Submit" value="Submit" />
  </p>
</form>
</body>
</html>


test2.jsp
---------------------
      <%@ page import="java.util.logging.*" %>
      <html>
      <body>
            <%
      Logger logger = Logger.getLogger("test2");
      if (request.getParameter("ip") !=null ) {
            logger.severe("REQPARAM is" +request.getParameter("ip"));
}
%>
</body></html>
0
 
rrzCommented:
What app server are using ?  I have trying on Tomcat 5.5  and I do see that ther is a upper limit. I haven't found it yet though.  Here is what I am using to test.  First page is just html.
<html>
</body>
<form name="empForm" method="post" action="http://localhost:8080/test.jsp">
                        <textarea name="dev" cols="55" rows="15">
</textarea>
<input type="submit"/>
</form>
</body>
</html>

and test.jsp is simply  

<%
  String dev = request.getParameter("dev");
%>
<%=dev%>

I  can't explain the limitation but then I see what your talking about here.    rrz
0
 
rrzCommented:
I am just paste different size text block into the textarea and getting redirected to  FakeServlet by Tomcat(which is unavailable) if it too large. Very strange ! A behavior I have not seen before. How about you TIm ?
0
 
TimYatesCommented:
(that's the same as my code rrz, just split into 2 files) ;-)

hehe
0
 
borislavmarkovCommented:
Hallo, I had once same problems, around 8kb of text brokes the text. I was using JETTY with JBOSS.
Is your situation the same.

I think I solved my problem with another trick like using:

******
request.getInputStream()
******

and reading rough data.
Try this solution.

Please tell us your environment OS/WEB Container/JVM/BROWSER/etc...
0
 
rrzCommented:
I was wrong. I don't see the problem. I mistakenly cut and pasted code.  When I cut and pasted plain text I had no problem with over 400 KB.
0
 
rrzCommented:
mytilig    Did you try  without looger code  ?  
0
 
mytiligAuthor Commented:
Hello all,
Thanks for all the time.

I removed all the loggers and found that my request.getParameter() seems to be fine and bringing in all the data.

I realize I am dealing with 2 separate issues here.
1. Logger cannot handle data larger than 7k
This is the reason I was getting all the errors I mention above.  so I have removed all the loggers from my code.

2. My main problem -- because of which I started the logging :(
My JVM does not seem to be able to handle when the string size exceeds 7k
My JSP code is

String temp = request.getParameter("ip");
emp.setDevTxt(temp);

emp.setDevTxt(temp) is the line that throws null pointer exception.

Xmx  is set to 1G, but not sure why the webserver still cannot handle string >7k

This is what I have so far.
0
 
rrzCommented:
Did you tell us what web app server you are using yet ? I can't see that post.  Which version of java ? Describe anything else that may shed some light on your problem.  I can't reproduce your problem here.  So the logger is out of the way ?  
>emp.setDevTxt(temp) is the line that throws null pointer exception.
Are you sure the parameter is being sent ?  Did you try borislavmarkov's suggestion ?     rrz
0
 
mytiligAuthor Commented:
Im sorry didnt mention webserver

SunOne 6.1
Solaris 5.9
Jdk 1.4.2_06

Yes the parameter is being set because it works for strings lesser than 7000 characters.
0
 
TimYatesCommented:
what does:

    emp.setDevTxt

do?

Java 1.4.2 doesn't have any problems with 7k strings...

You could try 1.4.2_10 (the latest) to be sure...?
0
 
rrzCommented:
>Yes the parameter is being set because it works for strings lesser than 7000 characters.
That is good logic. I think that why bris suggest what he did.  Do you need help implementing it ?  

Hi Tim, isn't it past your bed time ?  Good idea anyway.
He should first try it the way we did in your posts. If that works, then we must look at the code in "emp".
0
 
mytiligAuthor Commented:
YEs I tried request.getInputStream()  too and same issues.

(I thought I posted the result earlier, but apparently not)

The problem DOES NOT happen on my local SunOne webserver running on windows.
It happens on both my solaris machines that have SunOne webserver running.  It is the same code I am deploying to all 3 servers.

All javas are 1.4.2


Any known bug with java 1.4 build on solaris causing the issue?

emp.setDevTxt is just a bean class that has setter tag

      public void setDevPlanTxt1(StringBuffer devPlanTxt1) {
            this.devPlanTxt1 = devPlanTxt1;
      }

--Mythili (she)
0
 
rrzCommented:
>YEs I tried request.getInputStream()  too and same issues.
Could you elaborate ?   Did you send the request from a HTML page as I did above ?
When the request body exceeds 7000 characters , then suddenly it is null ?  So problem is before it reaches the JSP ?
0
 
borislavmarkovCommented:
I said I tried "request.getInputStream()" on jetty, not on SunOne, the author had not yet mentioned his environment.
Anyway, I suggest to change the encode type of your request.
in HTML please change enctype

<html action="..." enctype=".."> search for a better enctype and let's see how your request is handled.

Try with another enctype like:

ENCTYPE = "multipart/form-data" | "application/x-www-form-urlencoded"

0
 
TimYatesCommented:
mytilig, does the simple JSP here: http:Q_21810424.html#16434015  Work or not?
0
 
mytiligAuthor Commented:
Answering my own question here:
My code worked fine after increase the StackSize variable in magnus.conf
Thankyou all.
0
 
rrzCommented:
Good, then ask for this to be deleted.  
0
 
mytiligAuthor Commented:
No why should it be deleted?
Number of people have provided inputs and spent lot of time to help on this. Maybe some of the suggestions may help someone else.
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.