File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Discussion on doGet method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Discussion on doGet method" Watch "Discussion on doGet method" New topic

Discussion on doGet method

Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
Hi All,

What will be happen when we do not override doGet() method.

Thanks in advance
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

Did you try creating a servlet without overriding any of the http (get/post) ?

Did the request go the servlet? I suppose these are the questions in a beginners mind which should be tried and tested on your own.

Just that you can create a topic and get easy answers, will only make your ability to understand and troubleshoot your issues.

Any doubts after, with what you have tried, are always welcome.


Regards, Sud.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Abhay Choubey wrote:
What will be happen when we do not override doGet() method.

what is your observation?
Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34

According to me i am telling to the container that this servlet will not support HTTP get request. It is right

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
That's easy to test, no?
Abhay Choubey
Ranch Hand

Joined: Jun 02, 2011
Posts: 34
I have searched any studying the book and got this idea. if it is wrong than what is correct answer of this.

please help me

Sergey Baranov

Joined: Aug 27, 2005
Posts: 18

It's all in the documentation:

Overriding this method to support a GET request also automatically supports an HTTP HEAD request. A HEAD request is a GET request that returns no body in the response, only the request header fields.

When overriding this method, read the request data, write the response headers, get the response's writer or output stream object, and finally, write the response data. It's best to include content type and encoding. When using a PrintWriter object to return the response, set the content type before accessing the PrintWriter object.

Sergey Baranov
Vishal Trivedi
Ranch Hand

Joined: Sep 05, 2011
Posts: 57
Hi All,

This is my first reply so pkz excuse me for mistakes.

The doGet() and doPost methods are only supported by httpServlet.
So you can use them while creating an httpServlet

and the default implementation of these methods is that you get output saying that this method is not supported.

Please correct me if i am wrong

Thanks and Regards
German Gonzalez-Morris
Ranch Hand

Joined: Nov 16, 2009
Posts: 232

All these seven HTTP methods are supported: GET, POST, HEAD, TRACE , PUT, DELETE, OPTIONS
Although you'll probably only use POST and GET.

If you do not override doGet then you will get an error if sned a GET request:
in Tomcat, something like :

HTTP Status 405 - HTTP method GET is not supported by this URL
I agree. Here's the link:
subject: Discussion on doGet method
It's not a secret anymore!