www 4-7

Is this your test? Login to manage it. If not, you can create a quiz just like it.

This is a non-interactive preview of the quiz content.

1.
1 point
Match the method getContextPath to the following classes or interfaces
2.
1 point
Which types of objects are available to the jspInit() method?
3.
1 point
Which are true about the RequestDispatcher interface?
4.
1 point
Which method of HttpServletResponse is used to redirect an HTTP request to another URL?
5.
1 point
Which is most logically stored as an attribute in session scope?
6.
1 point
Given:
1. import javax.servlet.http.*;
2. public class MySessionListener
implements HttpSessionListener {
3. public void sessionCreated() {
4. System.out.println(“Session Created”);
5. }
6. public void sessionDestroyed() {
7. System.out.println(“Session Destroyed”);
8. }
9. }
What is wrong with this class?
7.
1 point
Which statements about session tracking are true?
8.
1 point
Match the method getAttribute to the following classes or interfaces
9.
1 point
Which types of objects can store attributes?
10.
1 point
Which of the following are NOT listener event types in the J2EE 1.4 API?
11.
1 point
What is the recommended way to deal with servlets and thread safety?
12.
1 point
Given a session object s with two attributes named myAttr1 and myAttr2, which will remove both attributes from this session?
13.
1 point
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?
14.
1 point
Given this DD element:
47.
48. *.jsp
49. true
50.
What does the element accomplish?
15.
1 point
Which of the following methods are declared in HttpServletRequest as opposed to in ServletRequest?
16.
1 point
When declaring a listener in the DD, which sub-elements of the element are required?
17.
1 point
Given a session object s, and the code:
s.setAttribute(“key”, value);
Which listeners could be notified?
18.
1 point
Choose the servlet code fragment that gets a binary stream for writing an image or other binary type to the HttpServletResponse.
19.
1 point
Which directives specify an HTTP response that will be of type “image/svg”?
20.
1 point
Which statements about HttpSession objects are true?
21.
1 point
Given this code from an otherwise valid HttpServlet that has also been
registered as a ServletRequestAttributeListener:
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. }
22.
1 point
Which statements about session timeouts are true?
23.
1 point
How would you use the HttpServletResponse object in a servlet to add a cookie to the client?
24.
1 point
Which method(s) can be used to ask the container to notify your application whenever a session is about to timeout?
25.
1 point
Given req is a HttpServletRequest, which gets a binary input stream?
26.
1 point
How should servlet developers handle the HttpServlet’s service() method when extending HttpServlet?
27.
1 point
Which HTTP methods are NOT considered idempotent?
28.
1 point
Given this JSP:
1. <%@ page import=”java.util.*” %>
2. The people who like
3. <%= request.getParameter(“hobby”) %>
4. are:

5. <% ArrayList al = (ArrayList) request.getAttribute(“names”); %>
6. <% Iterator it = al.iterator();
7. while (it.hasNext()) { %>
8. <%= it.next() %>
9.

10. <% } %>
11.
Which types of code are used in this JSP?
29.
1 point
Which statements about RequestDispatcher are true (where applicable, assume the RequestDispatcher was not obtained via a call to getNamedDispatcher())? (
30.
1 point
When using a RequestDispatcher, the use of which methods can often lead to an IllegalStateException?
31.
1 point
Which statements about listeners are true?
32.
1 point
Choose the servlet code fragment that would retrieve from the request the value of a cookie named “ORA_UID”?
33.
1 point
Match the method getCookies to the following classes or interfaces
34.
1 point
Which statements about ServletContext initialization parameters are true?
35.
1 point
Which statements about HttpSession objects in distributed environments are true?
36.
1 point
How would you set a header named “CONTENT-LENGTH” in the HttpServletResponse object?
37.
1 point
Given:
<%@ page isELIgnored=”true” %>
What is the effect?
38.
1 point
Which are true?
39.
1 point
Which interfaces define a getSession() method?
40.
1 point
Which statements about session attributes are true?
41.
1 point
Which methods are used by a servlet to handle form data from a client?
42.
1 point
Which statements about jspInit() are true?
43.
1 point
Given:
10. public class MyServlet extends HttpServlet {
11. public void doGet(HttpServletRequest request,
HttpServletResponse response)
12. throws IOException, ServletException {
13. // request.getSession().setAttribute(“key”, “value”);
14. // request.getHttpSession().setAttribute(“key”, “value”);
15. // ((HttpSession)request.getSession()).setAttribute(“key”, “value”);
16. // ((HttpSession)request.getHttpSession()).setAttribute(“key”, “value”);
17. }
18. }
Which line(s) could be uncommented without causing a compile or runtime error?
44.
1 point
How would servlet code from a service method (e.g., doPost() ) retrieve the value of the “User-Agent” header from the request?
45.
1 point
Which types define the methods getAttribute() and setAttribute()?
46.
1 point
Given that req is an HttpServletRequest, which snippets create a session if one doesn’t exist?
47.
1 point
Which calls provide information about initialization parameters that are applicable to an entire web application?
48.
1 point
If a client will NOT accept a cookie, which session management mechanism could the web container employ?
49.
1 point
Which HTTP methods are used to show the client what the server is receiving?
50.
1 point
Given:
13. public class ServletX extends HttpServlet {
14. public void doGet(HttpServletRequest req, HttpServletResponse resp)
15. throws IOException, ServletException {
16. HttpSession sess = new HttpSession(req);
17. sess.setAttribute("attr1", "value");
18. sess.invalidate();
19. String s = sess.getAttribute("attr1");
20. }
21. }
What is the result?