• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

enthuware ques HTTP method

 
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
 
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
 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE 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!
 
Rancher
Posts: 43016
76
  • 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.
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i always went wrong on these two questions...
 
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
 
What are you saying? I thought you said that Santa gave you that. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic