File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Request Parameters for GET and POST Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Request Parameters for GET and POST" Watch "Request Parameters for GET and POST" New topic

Request Parameters for GET and POST

Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 951

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


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.



Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Rodrigo Dinis
Ranch Hand

Joined: May 28, 2003
Posts: 40
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
<msg-body or payload>
It limits the query string length and is insecure way.

POST /myapp/servlet/MyServlet
<query string and msg-body or payload>
Its more secure and the query string is putted here automatically. The server side know that.

Rodrigo Dinis
Brasilia - BRASIL
ramaseshan T
Ranch Hand

Joined: Feb 17, 2005
Posts: 30
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..

Ramaseshan T<br />SCJP 1.4
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 951

I am trying something like this.

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

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.

[ May 12, 2005: Message edited by: Narendra Dhande ]
I agree. Here's the link:
subject: Request Parameters for GET and POST
It's not a secret anymore!