Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get request with out doGet()

 
Ganesh.P Ram
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is a GET request and there is no corresponding doGet() in our servlet, then what happens ?

I am thinking that at the time of servicing the request, the container throws an exception bcos the service() is not able to find the doGet(), is that right.

I found this question in one of the mock exams, the answer was the code compiles fine and an empty / blank page is shown.
 
Ganesh.P Ram
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So my question was, does showing a blank page indicate that there was some exception thrown by the container ?
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

yes that�s correct.

- That�s "fine" utilize HTTP GET METHOD without using doGet method.
- That�s "wrong" utilzing HTTP POST METHOD without using doGet method.

The blank page is because the container utilizes the implementation from Generic abstract class, but there is no real implementation, so blank pageis shown.

Hope it help you.

 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

ops (typo) :

- That�s "wrong" utilzing HTTP POST METHOD without using doPost method.
 
Ganesh.P Ram
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Felipe,
I got ur point.
But Pg.118 HFSJ says we will get that msg - how does that come ?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't agree that a blank page will always be shown; at best I think this is container-dependent (since the explicit behaviour isn't given in the spec.). The default behaviour for HttpServlet in Tomcat and Sun AppServer (the Reference Implementation) is to return the HTTP status code 405 ("Method Not Allowed") which indicates to the client that there is no implementation for that HTTP method type. This is not the same as throwing an exception, and not the same as delegating to the superclass (GenericServlet). Whether the server decides to return a default error page or a blank page is container-dependent; you can even choose to return your own custom 405 error page!

I'm dubious about the integrity of the question: certainly the code will compile fine because there are default implementations for each method (returning a 405 status code), but I don't agree (unless other conditions were stipulated) that a blank page is guaranteed.

If you really want to be current, take a look at the source code for HttpServlet in Glassfish (the new Java EE 5 reference implementation):

https://glassfish.dev.java.net/source/browse/glassfish/servlet-api/src/jakarta-servletapi-5/jsr154/src/share/javax/servlet/http/HttpServlet.java

Follow this link, then click "view file" under the latest version. This is the source code for HttpServlet, and therefore the default method implementations are in there!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic