• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ Edition 2 Final mock exam QNo:45

 
Niteen Patil
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given this fragment from a valid doGet() method:
12. OutputStream os = response.getOutputStream();
13. byte[] ba = {1,2,3};
14. os.write(ba);
15. RequestDispatcher rd = request.RequestDispatcher("my.jsp");
16. rd.forward(request, response);
Assuming that "my.jsp" adds the bytes 4, 5, and 6 to the response, what is the result?
A. 123
B. 456
C. 123456
D. 456123
E. An exception is thrown


Answer given is: B.

But on line no.15 , the method to get the RequestDispatcher is request.RequestDispatcher("my.jsp"); which should be request.getRequestDispatcher("my.jsp");
So, the answer should be E. An exception is thrown. Correct me if I am wrong.
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitinyanand Patil wrote:

But on line no.15 , the method to get the RequestDispatcher is request.RequestDispatcher("my.jsp"); which should be request.getRequestDispatcher("my.jsp");



I dont know the answer , but what you pointed you about Request Dispatcher .. It should give a compilation Error..not an Exception.
as there is no RequestDispatcher() method in request!
But then that's not mentioned. So we are pretty much back to square one! unless there is some error in the question.
 
Niteen Patil
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is a compiler error then there is no option to select for a correct answer
Thanks.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nitinyanand Patil wrote:If this is a compiler error then there is no option to select for a correct answer

Check whether there any errata on this.
 
Raoul Kalk
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure here, but writing to the response object and then forwarding, may that cause an exception?
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raoul Kalk wrote:Not sure here, but writing to the response object and then forwarding, may that cause an exception?

Yes, if you commit the response before forwarding.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic