File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes doGet and doPost() difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "doGet and doPost() difference" Watch "doGet and doPost() difference" New topic
Author

doGet and doPost() difference

Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
Please help me clarify the following questions if you can ---

1. I know doGet()'s limit is the length of query string. e.g if a user picks 5 hundred products from your product list, your server may not be able to sustain the query string length ? so, this length limit is server specific, right ?

2. can I pass and retrieve hidden variables using doPost() ?

3. If I use doPost() method only, but I still pass some parameters through URL like http://server/servlet/MyServlet?name=john Then in the doPost(), can I retrieve the "name" parameter ?

thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

1. Yes (also browser specific)

2. Yes

3. Yes


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
I can access the Query String parameter with doPost() method additional to the parameters supplied through HTML FORM. Why it is not true for the doGet() method. If I use doGet() method for the URL containing Query String and the FORM parameters, the query string is ignored. Why???


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The querystring is not ignored when you use doGet.

Browsers send 2 types of request (there are others but they're not commonly used by browsers) GET and POST.

GET requests send only headers. Parameters can be tacked onto the end of the URL. The values can only ever be text.

A typical get request (no querystring parameters);


A POST request is a little more involved. The headers are sent and then (if the server accepts it) the content of the post is sent up. The browser must send headers telling the server what the content type is and what it's length is.

A typical post:
The content comes after the headers...


In both cases the servlet container will look for query string parameters in the url. If the request is of type "POST" then the container will also look to see if the Content-Type is "application/x-www-form-urlencoded" and, if so, parse the content to pull the name=value pairs.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

BTW:
I was able to read those headers with the Live HTTP Headers plugin for Firefox.
A beginning developer can learn a lot about how the web works using a tool like this.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Technical differences aside, it's worth digging into the original intent for GET and POST (and the other commands.) Drastically abbreviated: GET should never modify any state, POST should submit data for update. Review the W3C description of the commands or Google for "rest architecture" or "restful architecture" for more details.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi Ben,

Your GET request headers showing 2 JSESSIONIDs. Can one request have simultenious 2 sessions?

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I wouldn't think so, but there they are.
I know you can have different path attributes but these don't.
Maybe someone else knows.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: doGet and doPost() difference