• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher question

 
Tyronne Fernando
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I got the following question from (http://www.javabeat.net/javabeat/scwcd/mocks/scwcd_1.4_mock_exam_questions_5.php)

Following is the code for doGet() method of TestServlet. Which of the given statements about it are correct?

public void doGet(HttpServletRequest req, HttpServletResponse res)

{
try
{
RequestDispatcher rd =
this.getServletContext().getRequestDispatcher("Login.jsp");// 1

rd.forward(req, res); // 2
}
catch(Exception e)
{
e.printStackTrace();
}
}

Select 2 correct options.
A.This will not compile.
B.This will compile but will not work as expected.
C.This code will work just fine.
D.It will compile but not work properly if //1 is replaced with:
RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");
E.It will compile and will work properly if //1 is replaced with:
RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");

C and E were given as the correct answers.

I think B and E are the correct answers, as a RequestDispatcher accessed from the ServletContext should have "/" when the pages are accessed.

I like to know some of your thoughts on this. Thanks in advance.

Cheers,
Tyronne
 
Christian Nicoll
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tyronne,

i think you are right und you 've give also the right reasons (missing /) for it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic