Mid1 Review2 SELECT THE BEST CHOICE (answer to the left of the question) 1. When a JSP is requested for the first time, the JSP a. b. c. calls the servlet that it is associated with calls the built-in request object is converted into a servlet 2. As you develop a web application, you typically use a. b. c. d. JSPs for presentation and processing servlets for presentation and processing JSPs for processing and servlets for presentation JSPs for presentation and servlets for processing 3. All but one of the following is true for a WAR (Web Archive) file. Which one is it? a. b. c. d. A WAR file is a JAR file. A WAR file contains all the directories and files for a web application. When you deploy an application with a WAR file, the web server must be running. To deploy an application with a WAR file, you copy it into its document root directory. 4. The servlets for a web application are stored in this directory and its subdirectories: a. b. WEB-INF WEB-INF\classes c. d. WEB-INF\lib WEB-INF\servlets 5. The web.xml file can do all but one of the following. Which one is it? a. b. c. d. Define initialization parameters for a servlet. Define initialization parameters for the entire application. Enable servlet mapping so a client can call a servlet using any URL pattern. Set the web server port for the application. 6. If you have to change the port that’s used by Tomcat, you make the change in the a. b. server.xml file web.xml file c. d. catalina.bat file startup.bat file 7. The following code <% String[] mailTypes = request.getParameterValues("mail"); %> a. b. c. d. e. returns the name of all request parameters from the mail.jsp page returns the first value of the mail parameter or null if none exist returns all values of the mail parameter or null if none exist returns the values of all request parameters from the mail.jsp page is invalid 8 .In general, you should use the Post method instead of the Get method when a. b. c. d. the request writes data to the server the request reads data from the server you want users to be able to include parameters in their bookmarks when you’re transferring 4 KB or less of data 9. To use your own Java class in a JSP, you can import the class with a a. JSP scriptlet c. JSP directive (50%) b. JSP expression d. JSP declaration 10. When a JSP is requested for the first time, the JSP engine does all but one of following. Which one is it? a. b. c. d. generates a servlet for the JSP generates the HTML code for the JSP creates one instance of the servlet class creates one thread 11. When a JSP is requested for the second time, the JSP engine a. b. c. d. creates a thread that has its own copy of the instance variables creates a thread that has its own copy of the local variables creates an instance of the JSP that has its own copy of the instance variables creates an instance of the JSP that has its own copy of the local variables 12. A servlet is a Java class that extends the a. b. Servlet class HttpGenericServlet class c. d. HttpServlet class HttpServletRequest class 13. In the code that follows, the servlet is mapped to <servlet-mapping> <servlet-name>DiagnoseTrouble</servlet-name> <url-pattern>/diagnostics/diagnoseTrouble</url-pattern> </servlet-mapping> a. b. c. d. the /diagnostics/diagnoseTrouble URL of the document root directory the /diagnostics/diagnoseTrouble URL of the current directory any URL in the /diagnostics/diagnoseTrouble directory of the document root directory any URL in the /diagnostics/diagnoseTrouble directory of the current directory 14. The init method of a servlet class is called a. b. c. d. the first time a servlet is requested but before the service method each time the servlet is requested but before the service method the first time a servlet is requested but after the service method each time the servlet is requested but after the service method 15. A session object is created a. b. c. d. every time a browser makes a request for a web page every time a browser requests a servlet every time a browser requests a jsp the first time a browser requests a servlet or JSP from a web site 16. A servlet can retrieve the current session object by using the getSession method of the a. b. HttpSession class response object c. d. the request object the ServletContext object c. to both servlets and JSPs 17. The current session object is available a. b. only to JSPs only to servlets 18. Which of the following statements is invalid? a. b. c. d. String name = session.getAttribute("fullName"); Book book = (Book) session.getAttribute("bookObj"); session.setAttribute("fullName", "Ted Andrews"); session.removeAttribute("fullName"); 19. When you use URL encoding for session tracking, you must a. b. c. d. e. convert all HTML pages in the application to JSPs use the encodeURL method to encode all URLs in the JSPs use the encodeURL method to encode all URLs in the servlets a and b above a, b, and c above 20. The cookie named mediaCookie in the following statement can be accessed by mediaCookie.setPath("/"); a. b. only the current directory the entire web application c. d. the entire web server anyone 21. The following Anchor tag demonstrates how to use <a href="/WorkServlet?shift=<%= shiftCode %>" > View your schedule </a> a. b. URL rewriting URL encoding c. d. hidden fields cookies 22. When you use hidden fields to pass parameters to a servlet or JSP, all but one of the following is true. Which one is it? a. b. c. d. the parameters aren’t shown in the URL the user can see the parameters by using the browser to look at the page’s source code you don’t have to store the parameters in the session object you can’t use URL encoding 23. If you use the MVC pattern with EL, a. b. c. d. the servlets create the JavaBeans and set the bean properties the servlets create the JavaBeans and the JSPs set the bean properties the JSPs create the JavaBeans and set the bean properties the JSPs create the JavaBeans and the servlets set the bean properties 24. The initParam implicit object lets you use EL a. b. c. d. to get the value of a context initialization parameter to get the value of a servlet initialization parameter to set the starting value of a context initialization parameter to set the starting value of a servlet initialization parameter 25. Which of the following is the correct EL code for getting the value of a cookie named userPreference? a. b. c. d. ${cookie.userPreference} ${cookie.userPreference.value} ${cookie.value.userPreference} ${cookie.userPreference[value]} FILL IN THE MISSING BLANKS (40%) (Telnet, HTTP, JSPs, HTMLs, I/O, business, properties, attributes, choose, scripting, getInitParameter, TCP, context, ServletContext, session, JSTL, include, web.xml, request, response, cookie, encodeURL, URL rewriting) 1. The (application) protocol that’s used by a client and a server to communicate in a web application is ________________________________________________. 2. When you use the Model 1 architecture, ________________________ handle both the request and response. 3. In the MVC pattern, the model consists of _________________________ objects. 4. When you use the MVC pattern, you often add ________________________ to the request object before you forward it to a JSP or another servlet. 5. To include a file in a JSP at compile-time, you use an include _____________________. 6. A parameter that’s available to the entire application is called a/an ___________________________ initialization parameter. 7. To get an initialization parameter, you use the ___________________________ method. 8. You can use getRealPath method of a/an ______________________________________ object to get the absolute path to a file that’s part of a web application. 9. To get the effect of an if/else statement with JSTL, you can use a/an _______________________ tag. 10. If you combine JSTL with EL and the MVC pattern, you should be able to remove most, if not all, of the __________________________ from your JSPs.