• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Question

 
Muks Sam
Ranch Hand
Posts: 47
Java MyEclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have quick question, if somebody can help.

I have a Servlet which has only doPost method and I am calling this servlet from a link in HTML page. What should be the result? I know its a basic question. But little confused, as I am only aware that the error will thrown stating "Method not supported".

But is it a case where it "Executes default implementation of the doGet method in GenericServlet"??

Can somebody help Please?

Thanks

Muks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But is it a case where it "Executes default implementation of the doGet method in GenericServlet"??

The doGet method is not in GenericServlet, but in HttpServlet (remember that GET, POST and others are HTTP methods). You are right to say that the default implementation will be executed, the one in HttpServlet. But do you know what's in there ? Does the container know what to do when a GET request comes, and you didn't override the doGet method ? It doesn't know what to do, so it sends an error to tell you that this http method is not supported by your servlet.
 
Muks Sam
Ranch Hand
Posts: 47
Java MyEclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Christophe Verre:

The doGet method is not in GenericServlet, but in HttpServlet (remember that GET, POST and others are HTTP methods). You are right to say that the default implementation will be executed, the one in HttpServlet. But do you know what's in there ? Does the container know what to do when a GET request comes, and you didn't override the doGet method ? It doesn't know what to do, so it sends an error to tell you that this http method is not supported by your servlet.

=========================================================
Hi Chris,

Thanks for your reply. So I was right that it will send the error rather than any "default execution". There's one mock exam that told me that "sending the error" is wrong and "default execution" is right, so I was confused.

Regards

Muks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's one mock exam that told me that "sending the error" is wrong and "default execution" is right, so I was confused.

That's tricky because the spec does not say if an error will be sent or not. All we know is that the default doGet method will be called. So I think that your mock is right.
 
Jettry Lee
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API-document i know that the doGet() method in HttpServlet is protected. So, in my opinion the "default execution" is sending an error.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the API-document i know that the doGet() method in HttpServlet is protected. So, in my opinion the "default execution" is sending an error

The service() method is called, not the doGet(). The container will do the necessary job to call doGet() when a GET method comes in. doXXX are called from the service() method, so even if it's protected, it will be called.
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aren't the doXXX methods in the HttpServlet class itself empty? So that if they are not overriden, just nothing will happen (no errors)?

Of course it's easy to check with code, but I'm a little bit too lazy right now
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they were empty, how would the container throw a "http method not supported" error ?
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, got it. Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic