Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Discussion on doGet method

 
Abhay Choubey
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

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

Thanks in advance
Abhay
 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Enjoy!!
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhay Choubey wrote:
What will be happen when we do not override doGet() method.

what is your observation?
 
Abhay Choubey
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Abhay
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's easy to test, no?
 
Abhay Choubey
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Abhay
 
Sergey Baranov
Greenhorn
Posts: 18
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vishal Trivedi
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic