Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request Parameters for GET and POST

 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to test the Servlet basics on the tomcat server. For the GET method, the request parameters are passed in the address line. I developed a small servlet which read all the parameters and display it. Working fine. I place these servlet as the action element in the HTML FORM and test for default GET and another POST method. Aslo working fine. BUT....

When I tried the following URL in HTML FORM action attribute using GET method

/myapp/TestServlet?name=narendra

while running, in the browsers address bar, the ?name=narendra is ignored and the FORM fields are appended. OK

Surprisingly, when I tried the same using POST method, The name parameter from the addtess bar is included in the parameter list along with the form parameters. I understand that the request paremeters for POST method are palced the the message body.

How?

Thanks
 
Rodrigo Dinis
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question are confuse, but I ll explain what I know about HTTP GET and HTTP POST, I hope that help you:
HTTP GET: the query String is putted on the request of the HTTP protocol, like this:

GET /myapp/servlet/MyServlet?name=Joao&address=Rua das Couves
<headers>
<msg-body or payload>
It limits the query string length and is insecure way.

POST /myapp/servlet/MyServlet
<headers>
<query string and msg-body or payload>
Its more secure and the query string is putted here automatically. The server side know that.
 
ramaseshan T
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Does GET request have a pay-load/body? Its stated in HFS (Page:125) that GET request doesn't have a body..

Pls clarify..
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying something like this.

<form action='/myapp/TestServlet?name=narendra' method=post>
<input name='name' type='text'>
.......................
<input type='submit>
</form>

while executing this HTML, the servlet shows the name valus as narendra and karteya (the input given through Form.

But when I change the method=get, it is showing me name values as karteya only.

I am confused why the post method display the values in query string in the above example and get method ignored it.

thanks
[ May 12, 2005: Message edited by: Narendra Dhande ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic