• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enthuware ques HTTP method

 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends one more question-


Following is the code for TestServlet (See exhibit). Assuming that it is not preloaded or preinitialized, which of the given statements about it are correct?

public class TestServlet extends HttpServlet
{
public void init()
{
}
public void service(HttpServletRequest req, HttpServletResponse res)
{
super.service();
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
{
//do something
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
//do something
}
}

options-
1.For any and every HTTP request, at the most 2 of its methods will be called
2.For any and every request, atleast 1 of it's methods will be called.
3.For any and every request, service() will be called.
4.For an HTTP PUT request, none of it's methods will be called.
5.For an HTTP PUT request, it'll throw an exception.

Ans:2,3
My ans was:2,5

I have understood that 2 and 3 are correct, but why is 5 not correct?? wont it throw an exception if we request a PUT method and the doPut method is not defined.
?
thanks,
mallika
 
Shrenik Sakriya
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mallika,

The doPut, doOptions, doTrace, doConnect etc etc have default implementation in the super class which is HttpServlet which is why no error will occurr.

Regards,
Shrenik Sakriya
 
mallika shah
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Shrenik..

I got your point.

mallika
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it given in the specs that the doPUT, doConnect etc have an implementation in the HttpServlet class?? Kindly let me know the page number for it in the specs!
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it given in the specs that the doPUT, doConnect etc have an implementation in the HttpServlet class?


You'll find that in the javadocs.
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i always went wrong on these two questions...
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There's no mechanism in servlet API for handling doConnect(),so it's not a part of HttpServlet

Refer :HFSJ page 108

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic