This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

doubt on RequestDispatcher

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have seen problem in question bank that is:
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");


i think answer are B,E.

But answers are C,E.

is it correct? can you give me some explanation upon it?

Regards,
koti
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked at the question and before I saw the answers, I assumed the correct choices were C and E. My reason would be that I don't see any reason why it would on work and would also work if the RequestDispatcher was created from the request object. I know there is a difference between the two ways that affects the path that can be used (I forget this and need to re-read up on it) but I don't think we have any information in the question that would make us think there would be a path problem.
 
koteswararao arvapalli
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan,
i am sure that "the path string passed to ServeletContext.getRequestDispatcher() must start with '/' "
what do you say?

Regards,
koti.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option c is incorrect. This code wont work as such.
If we get RequestDispatcher from ServletContext we cannot specify relative path in argument of getRequestDispatcher().
The path should start with forward slash.
So options B and E are correct.
 
Dan Walin
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks - I need to restudy that.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic