Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EPractice Lab mock exam 3 about request dispatcher forward 's url path.  RSS feed

 
Himai Minh
Ranch Hand
Posts: 1572
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The code snippet to access FrameworkViewSelector in controller is given below:
FrameworkViewSelector selector = FrameworkViewSelectorIml.getInstance();
String nextJSP = selector.getNextPage(request, FrameworkViewSelector.SUCCESS);
Next, the Front Controller servlet must send the request to nextJSP to generate the view.
Assume that the servlet variable request is assigned the current HttpServletRequest object and variable context is assigned
the webapp's ServletContext.
A. Dispatcher rd= context.getDispatcher(nextJSP);
rd.forwardRequest(request, response);

B. Dispatcher rd= request.getDispatcher(nextJSP);
rd.forwardRequest(request, response);

C. RequestDispatcher rd= context.getRequestDispatcher(nextJSP);
rd.forward(request, response);

D. RequestDispatcher rd = request.getRequestDispatcher(nextJSP);
rd.forward(request, response);

Given answer : D

I think the answer can be C as well even though only one option can be chosen.
The question does not say nextJSP starts with "/" or not.
If nextJSP starts with a "/", that means it is a relative path to the context .
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 3013
236
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!