• 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

Question ID :995549757220

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the code for LoginServlet. Assuming that it is not preloaded or preinitialized, which of the given statements about it is correct?
(Statements in the options refer to the methods defined in this class.)
//[code]
public class LoginServlet extends HttpServlet
{
public void init()
{
//initialize db.
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
{
//do something
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
//do something
}
}
//[code]
1) for 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, init() will be called
Answer is 1.
Why is it atmost 2 methods?
The first request for the servlet will call 3 methods right?
 
Bartender
Posts: 3647
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are partially right (if you mean service method which dispatchs to appropriate http method)
But read the question again. Do you see 'service()' method ? This question ask only about mentioned methods, because you can define 100 methods which are chained from doGet(), etc....
So, answer using code snippet above.
 
kavitha yalamanchili
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it.. thanks
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic