About Question com.enthuware.ets.scwcd.v5.2.278 :

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scwcd.v5.2.278 :

Post by ETS User »

Consider the code for doGet method of a servlet.

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException
{
String userId = null;
try
{
userId = loginUser(req);
}
catch(Exception e)
{
// 1 : log "Unknown User" and the exception to the log file.
}
if(userId != null)
{
//do something.
}
}

Which of the given LOCs can be inserted at //1 to log the message as well as the exception's stack trace?
1. req.log(e, "Unknown User");
2.req.log(e, "Unknown User");
3.this.getServletContext().log("Unknown User",e);
4.this.getServletContext().log(e, "Unknown User");
5.The stack trace of the exception cannot be logged using log(...) methods.

Correct answer is 3.
But I say it should also be 4.
As, in ServletContext we have message log(Exception e,String message)

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scwcd.v5.2.278 :

Post by admin »

Method in option 4 is deprecated. This should be added to the explanation.

thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests