What is the result of a client request of the Source servlet with no query string?

Click the Exhibit button.
// Source Servlet : Source.java
10. public class Source extends HttpServlet {
11. public void service(HttpServletRequest request,
12. HttpServletResponse response)

13. throws ServletException, IOException {
14. RequestDispatcher rd =
15. request.getRequestDispatcher(“/dest/Destination”);
16. rd.forward(request, response);
17. }
18. } // Filter : ParamAdder.java
12. public class ParamAdder implements Filter {// …
23. public void doFilter(ServletRequest request,
24. ServletResponse response,
25. FilterChain chain)
26. throws ServletException, IOException {
27. request.setAttribute(“filterAdded”, “addedByFilter”);
28. chain.doFilter(request, response);
29. } // …
50. } // Destination Servlet Destination.java
10. public class Destination extends HttpServlet {
11. public void service(HttpServletRequest request,
12. HttpServletResponse response)
13. throws ServletException, IOException {
14. String filterParam =
15. (String) request.getAttribute(“filterAdded”);
16. response.getWriter().println(“filterAdded = “
17. + filterParam);
18. }
19. }
Given the web application deployment descriptor elements:

11. <filter>
12. <filter-name>ParamAdder</filter-name>
13. <filter-class>com.example.ParamAdder</filter-class>
14.
</filter>

31. <filter-mapping>
32. <filter-name>ParamAdder</filter-name>
33. <servlet-name>Destination</servlet-name>
34. </filter-mapping>

55. <servlet-mapping>
56. <servlet-name>Destination</servlet-name>
57. <url-pattern>/dest/Destination</url-pattern>
58. </servlet-mapping>
What is the result of a client request of the Source servlet with no query string?

Click the Exhibit button.
// Source Servlet : Source.java
10. public class Source extends HttpServlet {
11. public void service(HttpServletRequest request,
12. HttpServletResponse response)

13. throws ServletException, IOException {
14. RequestDispatcher rd =
15. request.getRequestDispatcher(“/dest/Destination”);
16. rd.forward(request, response);
17. }
18. } // Filter : ParamAdder.java
12. public class ParamAdder implements Filter {// …
23. public void doFilter(ServletRequest request,
24. ServletResponse response,
25. FilterChain chain)
26. throws ServletException, IOException {
27. request.setAttribute(“filterAdded”, “addedByFilter”);
28. chain.doFilter(request, response);
29. } // …
50. } // Destination Servlet Destination.java
10. public class Destination extends HttpServlet {
11. public void service(HttpServletRequest request,
12. HttpServletResponse response)
13. throws ServletException, IOException {
14. String filterParam =
15. (String) request.getAttribute(“filterAdded”);
16. response.getWriter().println(“filterAdded = “
17. + filterParam);
18. }
19. }
Given the web application deployment descriptor elements:

11. <filter>
12. <filter-name>ParamAdder</filter-name>
13. <filter-class>com.example.ParamAdder</filter-class>
14.
</filter>

31. <filter-mapping>
32. <filter-name>ParamAdder</filter-name>
33. <servlet-name>Destination</servlet-name>
34. </filter-mapping>

55. <servlet-mapping>
56. <servlet-name>Destination</servlet-name>
57. <url-pattern>/dest/Destination</url-pattern>
58. </servlet-mapping>
What is the result of a client request of the Source servlet with no query string?

A.
The output “filterAdded = null” is written to the response stream.

B.
The output “filterAdded = addedByFilter” is written to the response stream.

C.
An exception is thrown at runtime within the service method of the Source servlet.

D.
An exception is thrown at runtime within the service method of the Destination servlet.

Explanation:



Leave a Reply 0

Your email address will not be published. Required fields are marked *