File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doGet and doPost() difference

 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Yes (also browser specific)

2. Yes

3. Yes
 
Narendra Dhande
Ranch Hand
Posts: 951
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ben,

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

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic