Page 1 of 1

About Question enthuware.jwpv6.2.1090 :

Posted: Sun Dec 23, 2012 8:18 am
by Ciprian Mihalache
I believe the statement is incomplete, because it does not specify the url used by the servlet.
Consider the following testing code:

Code: Select all

@WebServlet(urlPatterns = { "/servlet", "/p1/servlet", "/p1/p2/servlet", "/p1/p2/p3/servlet" })
public class TestServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		RequestDispatcher requestDispatcher = req.getRequestDispatcher("../html/copyright.txt");
		if (requestDispatcher != null) {
			requestDispatcher.include(req, resp);
		} else {
			resp.getWriter().println("RequestDispatcher is null");
		}
	}
}
The third answer is correct only in case the servlet is called with an url like "/p1/servlet". In case the url of the servlet is "/servlet", the RequestDispatcher is null and in case the url of the servlet is longer ("/p1/p2/servlet" for instance) the RequestDispatcher is not null, but there is a runtime error : FileNotFoundException at address "/p1/html/copyright.txt"
So, the servlet url must be specified in the question statement in order to keep the third answer valid.

Re: About Question enthuware.jwpv6.2.1090 :

Posted: Sun Dec 23, 2012 11:01 am
by admin
You are right. Option 3 is correct only in some situations and not all. The problem statement has now been changed to "Which of the following code fragments occurring in doGet method could possibly achieve this objective?"

The real exam also uses similar construct for the problem statement when an option is a possible solution in some unspecified situation.

thank you for your feedback!
Paul