When using a RequestDispatcher
, the use of which methods can often lead to an IllegalStateException
? (Choose all that apply.)
(Servlet v2.4 pg. 167)
Which statements about ServletContext
initialization parameters are true? (Choose all that apply.)
(Servlet v2.4 pg. 31)
A. | They should be used for data that changes rarely. | |
B. | They should be used for data that changes frequently. | |
C. | They can be accessed using
| |
D. | They can be accessed using
| |
E. | They should be used for data that is specific to a particular servlet. | |
F. | They should be used for data that is applicable to an entire web application. |
Which types define the methods getAttribute()
and setAttribute()
? (Choose all that apply.)
(Servlet v2.4 pgs. 32, 36, 59)
If a servlet is invoked using the forward
or include
method of RequestDispatcher
, which methods of the servlet’s request object can access the request attributes set by the container? (Choose all that apply.)
(Servlet v2.4 65-66)
Which calls provide information about initialization parameters that are applicable to an entire web application? (Choose all that apply.)
(Servlet v2.4 pg. 32)
A. |
| |
B. |
| |
C. |
| |
D. |
| |
E. |
| |
F. |
|
Which statements about listeners are true? (Choose all that apply.)
(Servlet v2.4 pg. 80)
A. | A | |
B. | An | |
C. | A | |
D. | A | |
E. | A |
Which is most logically stored as an attribute in session scope?
(Servlet v2.4 pg. 58)
A. | A copy of a query parameter entered by a user. | |
B. | The result of a database query to be returned immediately to a user. | |
C. | A database connection object used by all web components of the system. | |
D. | An object representing a user who has just logged into the system. | |
E. | A copy of an initialization parameter retrieved from a |
-Option A is incorrect because a query parameter is more typically used immediately to perform an operation.
-Option B is incorrect because such data is typically either immediately returned or stored in request scope.
-Option C is incorrect because (since it is not specific to a particular session) it should be stored in context scope.
-Option E is incorrect because servlet context parameters should stay with the ServletContext object.
Given this code from an otherwise valid HttpServlet
that has also been registered as a ServletRequestAttributeListener
:
(Servlet v2.4 pg. 199-200)
10. public void doGet(HttpServletRequest req, HttpServletResponse res) 11. throws IOException, ServletException { 12. req.setAttribute("a", "b"); 13. req.setAttribute("a", "c"); 14. req.removeAttribute("a"); 15. } 16. public void attributeAdded(ServletRequestAttributeEvent ev) { 17. System.out.print(" A:" + ev.getName() + "->" + ev.getValue()); 18. } 19. public void attributeRemoved(ServletRequestAttributeEvent ev) { 20. System.out.print(" M:" + ev.getName() + "->" + ev.getValue()); 21. } 22. public void attributeReplaced(ServletRequestAttributeEvent ev) { 23. System.out.print(" P:" + ev.getName() + "->" + ev.getValue()); 24. }
What logging output is generated?
A. |
| |
B. |
| |
C. |
| |
D. |
| |
E. |
| |
F. |
|
When declaring a listener in the DD, which sub-elements of the <listener>
element are required? (Choose all that apply.)
(Servlet v2.4 section 10.4, & 13.4.9 )
Which types of objects can store attributes? (Choose all that apply.)
(API)
Which are true? (Choose all that apply.)
(Servlet v2.4 pgs. 81-84)
A. | When a web application is preparing to shutdown, the order of listener notification is not guaranteed. | |
B. | When listener-friendly events occur, listener invocation order is not predictable. | |
C. | The container registers listeners based on declarations in the deployment descriptor. | |
D. | Only the container can invalidate a session. |
Which statements about RequestDispatcher
are true (where applicable, assume the RequestDispatcher
was not obtained via a call to getNamedDispatcher()
)? (Choose all that apply.)
(Servlet v2.4 pg. 65)
A. | A | |
B. | The only method in the | |
C. | Parameters specified in the query string used to create a | |
D. | The servlet to which a request is forwarded may access the original query string by calling | |
E. | The servlet to which a request is forwarded may access the original query string by calling |
What is the recommended way to deal with servlets and thread safety?
(Servlet spec p 27)
A. | Write the servlet code to extend | |
B. | Have the servlet implement | |
C. | Log all servlet method calls. | |
D. | Use local variables exclusively, and if you have to use instance variables, synchronize access to them. |
Given the following methods:
(API)
- getCookies
- getContextPath
- getAttribute
Match the methods above to the following classes or interfaces. Note that each method can be used more than once.
Which are true about the RequestDispatcher
interface? (Choose all that apply.)
(API)
A. | Of its two methods, | |
B. | Its methods take the following arguments: a resource, a request, and a response. | |
C. | Depending on the class whose method creates a | |
D. | Regardless of the class whose method creates a | |
E. | If your servlet invokes |