The most intelligent Java IDE
The moose likes Servlets and the fly likes DoGet() is must?. The Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "DoGet() is must?." Watch "DoGet() is must?." New topic
Author

DoGet() is must?.

rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 157
In Servlet,DoGet() is must?.What is the Reason?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 12765
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.

[SCWCD Wall of Fame] [SCBCD Wall of Fame] [My Blog]
All roads lead to JavaRanch
Meherdad Bomanbehram
Ranch Hand

Joined: May 28, 2007
Posts: 119
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

Joined: Aug 29, 2007
Posts: 157
But some time
doPost()
{doGet()}
Calling like this?.What is the reason for that?
sarathchandra chandala
Greenhorn

Joined: Sep 06, 2007
Posts: 9
when we want to provide both the services, we generally use like the above .
David O'Meara
Sheriff

Joined: Mar 06, 2001
Posts: 12332
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.


Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems. Jamie Zawinski
[JavaRanch FAQ] [Book Promotions] [DbTamer]
Ulf Dittmer
Sheriff

Joined: Mar 22, 2005
Posts: 28826
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.

cewolf - Java web chartsMy Android appsImageJ Plugins
David O'Meara
Sheriff

Joined: Mar 06, 2001
Posts: 12332
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

Joined: Apr 20, 2006
Posts: 3057
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!

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials]
 
jQuery in Action, 2nd edition
 
subject: DoGet() is must?.
 
IntelliJ open source