Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question from jweb+

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question ID :999982887730
Consider the following code:
public void LoggingServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
String theMessage = "Log test";
//1
}
}
Which of the following LOCs when inserted at //1 will put "Log test" in the log file?
1.log(theMessage);
2.req.log(theMessage);
3.res.log(theMessage);
4.this.getServletContext().log(theMessage);
5.this.servletConfig().log(theMessage);
The correct answers given are 1 and 4.
and as the explaination they have given the following line:
The log() methods are provided by ServletRequest and ServletContext interface.
As per servlet API doc ServletRequest doesn't have log method.
Also why 1 is correct ans?
thanks,
Trupti
 
Rekha Polisetty
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Log methods are provided in GenericServlet and ServletContext.
So 1 and 4 are correct
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,& that's precisely why 2 is incorrect.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic