• Post Reply Bookmark Topic Watch Topic
  • New Topic

DoGet() is must?.

 
rex tony
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Servlet,DoGet() is must?.What is the Reason?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Servlet,DoGet() is must?.What is the Reason?

doGet is here to process http GET request, so if you think that you don't need it (for example if you want to treat only POST requests), you don't have to override it.
 
Meherdad Bomanbehram
Ranch Hand
Posts: 142
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
As per the servlet specs DoGet is not a must .If you do not want anyone to access the servlet via typing the URL in the address bar you could just implement the DoPost method and inb the Form method tag that would call this servlet mention it as "Post"
 
rex tony
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But some time
doPost()
{doGet()}
Calling like this?.What is the reason for that?
 
sarathchandra chandala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when we want to provide both the services, we generally use like the above .
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sarathchandra chandala:
when we want to provide both the services, we generally use like the above .


Not quite, when you want both GET and POST to behave the same, you can do that. In practice I try to avoid it. It is completely valid to have them behave differently.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
It is completely valid to have them behave differently.

And to take this a step further, if you want to create a servlet that behaves according to the HTTP specification, then GET and POST should do different things.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf, don't let me half-answer a question

Traditionally there where distinct uses for GET, POST and other HTTP message types, but over time many have fallen into rare usage and GET and POST have often been treated as interchangeable.

Going back to their original intents, GET was designed to be used for 'repeatable' requests, commonly called 'idempotent'. If you browse a catalogue, all 'browse' operations would be expected to be repeatable.

POST operations would involve state changes and not designed for repeating. Logging in, purchasing, registering etc would be POST operations.

While both involve sending and receiving data over HTTP, there are subtle differences that can encourage the choice between ond message type and another.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow.. That's where the experience speaks. Thank you David for providing the extra-but-required-to-know the important information!

Thanks Ulf for triggering David!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!