Page: 5
Unit- 3: The Web Container Model
Q13.You want to create a filter for your web application and your filter will implement javax.servlet.Filter. Which two statements are true? (Choose two.) A. Your filter class must implement an init method and a destroy method. B. Your filter class must also implement javax.servlet.FilterChain. C. When your filter chains to the next filter, it should pass the same arguments it received in its doFilter method. D. The method that your filter invokes on the object it received that implements javax.servlet.FilterChain can invoke either another filter or a servlet. E. Your filter class must implement a doFilter method that takes, among other things, an HTTPServletRequest object and an HTTPServletResponse object. Answer: A, D Q14. 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> ... 24. <filter-mapping> 25. <filter-name>ParamAdder</filter-name> 26. <servlet-name>MyServlet</servlet-name> 27. <!-- insert element here --> 28. </filter-mapping> Which element, inserted at line 27, causes the ParamAdder filter to be applied when MyServlet is invoked by another servlet using the RequestDispatcher.include method? A. <include/> B. <dispatcher>INCLUDE</dispatcher> C. <dispatcher>include</dispatcher> D. <filter-condition>INCLUDE</filter-condition> E. <filter-condition>include</filter-condition> Answer: B Q15. Your web application uses a simple architecture in which servlets handle requests and then forward to a JSP using a request dispatcher. You need to pass information calculated by the servlet to the JSP; furthermore, that JSP uses a custom tag and must also process this information. This information must NOT be accessible to any other servlet, JSP or session in the webapp. How can you accomplish this goal? A. Store the data in a public instance variable in the servlet. B. Add an attribute to the request object before using the request dispatcher. C. Add an attribute to the context object before using the request dispatcher. D. This CANNOT be done as the tag handler has no means to extract this data. Answer: B
Page: 5
1
2
3
4
5
6
7
8
9
10
|