File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes DoGet() is must?. 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é
Marshal

Joined: Nov 24, 2005
Posts: 14361

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.


[SCBCD Wall of Fame] [My Blog]
All roads lead to JavaRanch
Help Japan. Make a donation.
Meherdad Bomanbehram
Ranch Hand

Joined: May 28, 2007
Posts: 130

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
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.


[ JavaRanch FAQ ][ Book Promotions ][ DbTamer ][ BumperStickers ][ JavaRanch Badges ]
Ulf Dittmer
Marshal

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


Android appsImageJ pluginsJava web charts
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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: 3287

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] [Java Coding Guidelines]
 
 
subject: DoGet() is must?.
 
developer file tools