aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes get request with out doGet() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "get request with out doGet()" Watch "get request with out doGet()" New topic
Author

get request with out doGet()

Ganesh.P Ram
Ranch Hand

Joined: Dec 22, 2005
Posts: 41
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
Ganesh.P Ram
Ranch Hand

Joined: Dec 22, 2005
Posts: 41
So my question was, does showing a blank page indicate that there was some exception thrown by the container ?
Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
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.



SCJP | SCWCD | SCBCD | SCWSD 5 | SCEA (I) 1.4 | SCEA 5 | IBM SOA 669
Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
hi,

ops (typo) :

- That�s "wrong" utilzing HTTP POST METHOD without using doPost method.
Ganesh.P Ram
Ranch Hand

Joined: Dec 22, 2005
Posts: 41
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

Joined: Mar 27, 2003
Posts: 836
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!


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get request with out doGet()
 
Similar Threads
servlet methods
doPost(), doGet()
Is it a POST or GET request?
calling java inside a servlet
Error 405