• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question ID :995549757220

 
kavitha yalamanchili
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?
 
Mikalai Zaikin
Ranch Hand
Posts: 3371
12
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic