• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doGet and doPost() difference

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Yes (also browser specific)

2. Yes

3. Yes
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Evildoers! Eat my justice! And this tiny ad's justice too!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic