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

Why not RequestDispatcher?

 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following code for the doStartTag() method of a Tag:
Which of the following lines of code can be placed at LINE 1 above, so that the request can be forwarded to page2.jsp?

1)RequestDispatcher rd = request.getRequestDispatcher("page2.jsp"); rd.forward(request, response);

2)pageContext.forward("page2.jsp");

3)RequestDispatcher rd = pageContext.getRequestDispatcher("page2.jsp"); rd.forward(request, response);

4)request.forward("page2.jsp");

5)None of these.

The correct answer given here is 2. I agree but why the answer 1 is incorrect.
This is from Enthuware.
Please advice.
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TagSupport class have implicit variable named pageContext from which
you can make your forwards.

it is servlet in which you do use request-dispatcher to forward.Utterly
speaking tag class is not servlet so you have to use forward method
which takes single parameter to perform your task.

so the answer 1 is wrong.

best regards,
omi
[ August 31, 2008: Message edited by: omi sharma ]
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks OMI
 
Krzysztof Koziol
Ranch Hand
Posts: 133
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by omi sharma:


so the answer 2 is wrong.



The 1st answer is wrong. The 2 seems to be ok.
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea you are right ,I mistakenly did that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic