Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling of post form data�

 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am little bit confused about - How the data is handled in the case of Post request, if the parameters are appended to the query string and also data is present in the body? Notes from Mikalai Zaikin says that(may be useful to clarify the above one)

" The following are the conditions that must be met before post FORM data will be populated to the parameter set:

The request is an HTTP or HTTPS request.

The HTTP method is POST.

The content type is application/x-www-form-urlencoded.

The servlet has made an initial call of any of the 'getParameter' family of methods on the request object.

If the conditions are not met and the post form data is not included in the parameter set, the post data must still be available to the servlet via the request object's input stream. If the conditions are met, post form data will no longer be available for reading directly from the request object's input stream. "

Thanks in Advance
 
Chandra Atla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Narasimha Rao,

Here is an excerpt from servlet 2.4 spec, which answers your question.


Data from the query string and the post body are aggregated into the request
parameter set. Query string data is presented before post body data. For example,

if a request is made with a query string of a=hello and a post body of
a=goodbye&a=world, the resulting parameter set would be ordered a=(hello,
goodbye, world).

Thanks,
Chandra A
[ October 04, 2005: Message edited by: Chandra Atla ]
 
Lux Gupta
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I dont think that any query string goes with the post request. The only way the parameters are carried is the payload i.e. the parameters are present in the message body.
Thanks
 
Chandra Atla
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lux Gupta,

To test this, I have created a sample html and a jsp.

=============
TestPost.html
=============

<html>

<body>

<form name=myform method=post action="/jsp/TestPost.jsp?a=hello">

<input type=checkbox name="a" value="good"> First Value
<input type=checkbox name="a" value="boy"> Second Value

<input type=submit>

</form>

</body>

</html>

=============
TestPost.jsp
=============

<html>

<body>

<%

String[] avalue = request.getParameterValues("a");

for(int i=0; i<avalue.length; i++)
{
out.println("i="+i+" "+avalue[i]);
}
%>

</body>

</html>

When I submit the form with both the check boxes checked, I got the following output: i=0 hello i=1 good i=2 boy

So, Query string data is presented before post body data, if the query string has some data as shown above.

Thanks,
Chandra A
 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here the question is how to get the post form data, one way is through request object's input stream(request.getInputStream()) and the other way is using getParameter() method. In the notes(Mikalai Zaikin ) it states that if certain conditions are meet the data is not available throught request object's input stream. Is that means, Can't i use request object's input stream to get the data unconditionally?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic