Meaningless Drivel is fun!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doGet method 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 "doGet method" Watch "doGet method" New topic
Author

doGet method

sunitha nerevetla
Greenhorn

Joined: Sep 18, 2003
Posts: 23
In some mock exams, i saw that in the servlet which extends HttpServlet there would be no doGet method but the user invokes get methods either by clicking a link or typing the url in the browser address line. Now the answers would be
1. Throws error since no doGet method defined.
2. Invokes the default doGet method from HttpServlet.

I feel the second answer is right but the answer is other way. Is that right?
Ritu varada
Ranch Hand

Joined: Sep 08, 2004
Posts: 117
Hi Sunitha,
In your servlet, you have to either override doGet or doPost.(99.9% of the time!). If you don't override doGet and say, you just click a link, the container will throw an error since you don't have the doGet method defined. Hope this helps.


SCJP,SCWCD(1.4)
sunitha nerevetla
Greenhorn

Joined: Sep 18, 2003
Posts: 23
Ritu, Thanks for the reply.
I would implement doPost but not doGet, but doesn't the doGet method of HttpServlet will be executed since i haven't overridden the method from HttpServlet i would assume the default implementation of HttpServlet will be executed. I haven't seen in the API, that the doGet from HttpServlet is abstract method.
Shourya Kalinga
Greenhorn

Joined: Dec 14, 2004
Posts: 19
Sunitha,

You are right. doGet from HttpServlet is invoked when you call doGet on a servlet where there is no implementation provided. Both of your answers should be correct, if a slight modification is done

1. Throws error[to the client] since no doGet method defined.[The error may be - HTTP method GET is not supported by this URL]

2. Invokes the default doGet method from HttpServlet.

Hope that helps.

Shourya


SCJP 1.4<br />SCWCD 1.4
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hello,

I think both the answers should be correct. If I does not implement the doGet(), the same from the parent will be invoked ( Java Rule). But the default implementation of doGet() method is container dependent and usually throw Server Error ( I Remember 500).

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
shankar valiinaykam
Greenhorn

Joined: Jan 21, 2005
Posts: 23
Hi Sunita,

Even I had the similar kind of doubt. Did u get the precise answer for it? Other replies are much more confusing to me by sayin' both are correct. Is this what u r telling , dudes? Default doGet() in HttpServlet is called which throws errors if I dont override doGet()!!!

Oh my gosh!!! One reply says, it is vendor dependent!!! I am under the impression that HttpServlet is a concrete class. How can vendor touch that by any means in this world?

Shankar
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hello,

The HttpServlet is abstract class according to the specification provided by Sun. Also the implementation of the J2EE framework is provided by the Vendor and not by the sun.

I am using Tomcat 5. It is giving me following error message.

HTTP Status 405 - HTTP method GET is not supported by this URL

--------------------------------------------------------------------------------

type : Status report

message : HTTP method GET is not supported by this URL

description : The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28


Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doGet method