• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPost and doGet

 
Ryan Crow
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry if this sounds too stupid (maybe it does coz i cant seems to find any sollutions to this anywhere else)..
but can anyone explain the differences between doPost and doGet?
as far as i understand it, doPost has the parameter embedded while doGet has it appended to the url, thus revealing the value. anything else in concern? so why doGet when we have doPost?
as for implementations, does both applied the same codes whereby the form action=POST/GET and the servlet declare doPost/doGet, with both retreiving the values through request.getParameter("userid"); ?
any sample codes of both implementations would be very welcome...

thanks all.
cheers,
ryan.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ryan,
Do a search on 'doGet doPost difference' on this forum and you will get 14 hits.
hth,
bear
 
Ryan Crow
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks fer the pointer, bear. me bad for not doing a prior search through this forum.
i can understand the nature of both function... but when it comes to implementation and codings, how is it different in the client and servlet side between both?
does not post method still receive parameter value through request.getParameter("UserID"); ??

further pointers needed. thx.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does not post method still receive parameter value through request.getParameter("UserID"); ??

Yes, the request object hides any difference from you so you process the params in the exact same fashion.
In fact, in servlets in which it doesn't matter whether it's a get or a post (which is most that I've ever written), the doGet method immediately calls the doPost method and processing happens there.
hth,
bear
[ June 09, 2003: Message edited by: Bear Bibeault ]
 
Calina Cazangiu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan,
One reason for having doGet and not only doPost is to be able to bookmark the page that you access with doGet.
Calina
 
Ryan Crow
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the pointers guys...
i still dun know where did i go wrong... i was doing fine with doGet, having the site passing form data to the servlet...
but then again when i switch to doPost (all i do is change the <FORM ACTION="totheservlet" METHOD="POST"> method part from originally GET to POST now. and at the servlet side, the doGet function is also changed to doPost... and later calling String USerID = request.getParameter("UserID"); (still the same with both get and post)
now when everything was in get method, my servlet retrieve the data just fine. but when it is then switched to post... my getParameter returns null...
any idea where did i screw up? it's suppose to be so simple but it doesnt work that way for me... so ppl find it hard to diagnose as such things are not meant to be screwed up easily .
any suggestion on where to look would be appreciated.
 
Calina Cazangiu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try to call request.getParameterNames() to make sure you haven't somehow misspelled the parameter name?
 
Ryan Crow
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dun think mis-spelling the names would be possible, coz the same code is working fine with the doGet method...
and i double check the spellings.
now where the heck does it went wrong? or is there anything in particular to set with tomcat im using?
easier still, can anyone post me a basic doPost code both the web form portion and the servlet portion?
 
Calina Cazangiu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, sometimes visually checking the code is not 100% proof. I've seen this so many times with my code and others'. That's why when you're stuck you need to play with the code - add some print statements, rewrite the entire piece of code, and so on...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic