Question ID :996245849311
Consider the code for two
servlets of the same web application.
//In file LoginServlet.java
public class LoginServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
String userid = loginUser(req);
req.getSession().setAttribute("userid", userid);
}
}
//In file ReportServlet.java
public class ReportServlet extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException
{
String userid = (String) req.getSession().getAttribute("userid");
if(userid != null) generateReport(req, res);
}
}
Assuming that loginUser() and generateReport() are valid methods, which of the following statements about these servlets are true?
1)ReportServlet.java won't compile
2)Method generateReport() will never be executed
3)Method generateReport() will be executed only if a post request is sent to LoginServlet before ReportServlet
4)Share-session property should be difined to true in web.xml for ReportServlet to get 'userid'
5)None of the above
it says the correct answer is 3)
However, I was under the impression that doPost() throws IOException, ServletException - so they should both fail to compile!?
but I could be getting horrifically confused...
Any help would be much appreciated!
Rowan