aspose file tools*
The moose likes Servlets and the fly likes question about doGet not present.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "question about doGet not present.." Watch "question about doGet not present.." New topic
Author

question about doGet not present..

cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
Hi,
Here's the following code:

In one mock exam, they ask for the type of response when the following url is asked:
http://localhost:8080/test/servlet/com.baboon.servletmodel.TestServlet?param=12
The author says blank page witthout error.
I've tested it and i received a 405 error: http method GET not supported by this URL.
So who is right, and is there any default implementation of GET method provided by the container in the case of no one is implemented by the developer?
Thanks in advance,
Regards,
Cyril.


SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I believe the 'real world' experience is the correct answer (browser receives a 405).

Any exam (mock or not) that asks you what a browser screen should look like, is IMHO, rubbish.

If you have friendly error messages turned on in IE, you'll get a different looking screen than if you have them turned off. If you're using an old netscape version, you might get a popup dialog that says "page contained no data", while other browsers present a blank page. Sometimes when you view the source, it contains an empty <html><body></body></html> other times, it's completely blank.

Grr!
cyril vidal
Ranch Hand

Joined: Jul 02, 2003
Posts: 247
Hi Mike,
thanks for your response.
What I still not understand is why an exception is generated.
Assume the following asserts are correct:
GenericServlet has an abstract service(ServletRequest, ServletResponse) method. HttpServlet extends GenericServlet and provides a concrete implementation of the service() method. It also provides the empty implementation for the doXXX() methods.
There's anyway an empty implementation of doGet method provided by the container for the class HttpServlet, so why an exception is thrown?
What is also the utility of such a default implementation?
Thanks for your lignt on this topic,
Regards,
Cyril.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I don't have the source in front of me, so I'm not sure, but here's how I speculate it might be so:

public abstract class HttpServlet contains a whole bunch of protected methods (which are not themselves abstract).

doGet and doPost are two such methods.

their default implementation is to throw a 405 'not supported' exception.

When you subclass HttpServlet, and then provide your own doGet or doPost, you are overriding the method and 'supporting' it.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

yup, i've just decompiled the HttpServlet class found in servlet.jar in Tomcat's common/lib folder.

When your servlet provides a doGet() method, but not doPost(), the supercalss doPost() is used, which will sendError(405).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about doGet not present..