Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

HFSJ Edition 2 Final mock exam QNo:45

 
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.
 
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.
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • 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.
 
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
Posts: 4107
72
Hibernate Fedora Chrome
  • 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.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic