File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem in Mock exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem in Mock exam" Watch "Problem in Mock exam" New topic

Problem in Mock exam

Gurukant Desai
Ranch Hand

Joined: Apr 07, 2008
Posts: 56
Hi Friends,

One More question no.7 from javabeat's mock exam no.5.
7.Following is the code for doGet() method of TestServlet. Which of the given statements about it are correct?

public void doGet(HttpServletRequest req, HttpServletResponse res)




RequestDispatcher rd = this.getServletContext().getRequestDispatcher("Login.jsp"); // 1

rd.forward(req, res); // 2


catch(Exception e)





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");

Answer given are C,E where as I think A,E are correct
Reason:- From mikalai's note I found that "The ServletContext.getRequestDispatcher method takes a String argument describing a path within
the scope of the ServletContext. This path must be relative to the root of the ServletContext and begin
with a '/'."

Please reply whether I am right/wrong?
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246

You're right. It should be A & E. If you use without '/' (ie for ServletContext) you will get compilation error.

Thanks, Naveen.
I agree. Here's the link:
subject: Problem in Mock exam
It's not a secret anymore!