JSP 2.0 Test

Test Answers:

1. Read the following code snippet and answer the question based upon it:

<taglib>
    <taglib-uri>
    http://www.yourcompany.com/you TagLibrary
</taglib-uri>
  <taglib-location>
      /WEB-INF/yourTagLibrary.tld
      </taglib-location>
  </taglib>

From the statements given below, which one applies to the code snippet?
Answers:
• The taglib directive can reference a TLD by name
• This tag goes into the WEB-INF/myApplication/web.xml file
• This definition is incorrect because the taglib-uri should have been uri
• This definition is incorrect because the taglib should have been tag
2. Which method is called by the servlet container just after the servlet is removed from service?
Answers:
• public void finalize() {// code...}
• public void destroy() {// code...}
• public void destroy()throws ServletException {// code...}
• public void finalize()throws ServletException {// code...}
3. Which statement is true regarding ServletContext Initialization Parameters in the deployment descriptor?
Answers:
• They are accessible by all servlets in a given web application
• They are accessible by all servlets in a given session
• They are accessible by all servlets in a given HTTP request
• They are accessible by all servlets in a given container
4. Which method in the HttpServlet class corresponds to the HTTPPOST method?
Answers:
• postHttp
• doPost
• post
• getPost
5. What is the file name of the WebApp deployment descriptor?
Answers:
• web.xml
• deploy.xml
• init.xml
• config.xml
6. What is the WebApp deployment descriptor element name for the Servlet Context Initialization Parameters?
Answers:
• <context-init-param>
• <context-param>
• <init-param>
• <context-init>
7. With regard to the destroy lifecycle method, identify the correct statements about its purpose or about how and when it is invoked.
Answers:
• It gives the servlet an opportunity to clean up resources
• Like try-catch, it is called upon an exception
• It is rarely used but can be called to remove a servlet from memory
• It isn't called if the server crashes
8. How would you use a bean in a JSP page?
Answers:
• <jsp:useBean name="houseLotBean" scope="response" class="session.Realestate"/>
• <jsp:useBean id="houseLotBean" scope="session"><jsp:useBean>
• <jsp:useBean id="houseLotBean" scope="session" class="session.Realestate"/>
• <jsp:useBean scope="session" class="session.Realestate"/>
9. Which of the following is the name of the cookie used by Servlet Containers to maintain
session information?
Answers:
• SESSIONID
• SERVLETID
• JSESSIONID
• CONTAINERID
10. Which design pattern reduces network traffic by acting as a caching proxy of a remote object?
Answers:
• DataAccess Object
• Model-View-Controller
• Value Object
• Business Delegate
11. Assuming the tag library is in place and the tag handler is correct, which of the following is the correct way to use a custom tag in a JSP page?
Answers:
• <yourLibrary="whatColorlslt" color="red"/>
• <yourLibrary:whatColorlslt color="red"/>
• <yourLibrary color="red"/>
• <yourLibrary.whatColorlslt color="red"/>
12. What output will be sent to the browser by the following code snippet?

   <!--
    Que <%="Reader"%>
   -->
Answers:
• 'Que Reader' within HTML comment markers
• This will cause an error
• Que <%="Reader"%> within HTML comment markers
• This is a comment so it is ignored by the container
13. Which of the following are used by Servlet Containers to maintain session information?
Answers:
• Cookies
• Hidden form fields
• HTTPS protocol information
• URL rewriting
14. Read the following code snippet:

1 <libraryPrefix:handlerName parameterNAme="value">
2 <%=23*counter %>
3 <b>Congratulations!</b>

Which of the following is the correct way to complete the above code snippet?
Answers:
• </libraryPrefix:handlerName>
• </libraryPrefix:handlerName paremeterName="value">
• </handlerName>
• <libraryPrefix>
15. In which directory do you place any auxiliary JAR files?
Answers:
• WEB-INF/servlets
• WEB-INF/jar
• WEB-INF/classes
• WEB-INF/lib
16. Which statements are true regarding ServletContext Init Parameters in the deployment descriptor?
Answers:
• They are set at deployment-time, but accessed at run-time
• They are accessible from any session within that context
• They are not set at deployment-time, but accessed at run-time
• They are set at deployment-time and can be updated at run-time
17. With regard to the servlet context listener, which of the following methods is valid?
Answers:
• contextListenerEvent
• contextListenerInitialized
• contextInitialized
• contextListenerDestroyed
18. Assuming the servlet method for handling HTTPGET requests is doGet(HttpServletRequest req, HTTPServletResponse res), how do you get a request parameter in that servlet?
Answers:
• String value=req.getInitParameter(10);
• String value=req.getInitParameter("product");
• String value=res.getParameter("product");
• String value=req.getParameter("product");
19. Assume the custom tag is GLOOP and the prefix is TWONG. Which of the following is the syntax for an empty custom tag?
Answers:
• <TWONG:GLOOP/>
• <GLOOP:TWONG/>
• <GLOOP:TWONG></GLOOP:TWONG>
• <TWONG:GLOOP></TWONG:GLOOP>
20. Which two of the following statements are best associated with the HTTPPOST method?
Answers:
• This HTTP method is the one most frequently used by browsers
• There is no limit on how much data this HTTP method can send
• There is a limit on how much data this HTTP method can send
• This method is most often used to submit form data
21. Which two statements among the following apply to redirecting a HTTP request to another URL?
Answers:
• The path must be absolute
• The path must be relative
• The redirect method must be called before the response body is committed, otherwise an IllegalStateException is thrown
• The path may be relative or absolute
22. Which of the following is not a JSP implicit object?
Answers:
• out
• in
• response
• page
23. Which of the following is the listener interface for servlet context attributes?
Answers:
• ContextAttributeListener
• ServletContextAttributeListener
• ServletAttributeListener
• ServletContextListener
24. Which of the following statements are true regarding the HTTP GET method?
Answers:
• There is a limit on how much data this HTTP method can send
• There is no limit on how much data this HTTP method can send
• This HTTP method is the fastest
• This HTTP method is used when you click on an HTML link
25. What is Template Data?
Answers:
• The JSP blueprint or pattern
• The plain text (such as HTML) outside JSP tags(non java) in a JSP page
• The taglib XML namespace
26. Which of the following options is a valid declaration?
Answers:
• <%! String name="Patricia" %>
• <%! String name="Patricia"; %>
• <% String name="Devyn" %>
• <% public String name="Devyn"; %>
27. Which of following interfaces can make a servlet thread safe?
Answers:
• Runnable
• synchronization
• Servlets can't be made thread safe
• None of the above
28. Which statement is true regarding a servlet context listener?
Answers:
• An object that implements a context listener is notified when its request objects are created or destroyed
• An object that implements a context listener is notified when its Web App context is created or destroyed
• An object that implements a context listener is notified when its Web App deployment descriptor defines it to be notified
• An object that implements a context listener is notified when its sessions are created or destroyed
29. Which of the following statements are true regarding declaring a servlet instance in a deployment descriptor?
Answers:
• The tags are nested within <web-app> tags
• The tags do not define parameters
• The tags are <servlet-instance></servlet-instance>
• It specifies the fully qualified class name of the servlet
30. Which of the following statements are true regarding the structure of a WebArchive file?
Answers:
• It has a jar extension
• It is a JAR archive of the WebApplication structure
• It has a war extension
• It is extracted by the container upon the first call to any�servlet it contains
31. Which of the following options is a valid expression?
Answers:
• <%! String name="Patricia" %>
• <%! String name="Patricia"; %>
• <%=(new java.util.Date()).toLocaleString() %>
• <% public String name="Devyn"; %>
32. What does the container do with the following code snippet?

<!--#include file="somefile.html"-->
Answers:
• The container passes this line of code through to the client
• The container includes this file statically
• The container includes this file dynamically
• The container will throw an exception
33. Which method in the HttpServlet class corresponds to the HTTPPUT method?
Answers:
• put
• doPut
• httpPut
• putHttp
34. Which of the following is a JSP implicit object?
Answers:
• objRequest
• Request.send
• request
• servlet
35. Which design pattern is used to decouple presentation from core data access functionality?
Answers:
• BusinessDelegate
• DataAccess Object
• ModelView Controller
• Value Object
36. In which directory do you place servlet class files?
Answers:
• WEB-INF\servlets
• webapp\servlets
• WEB-INF\classes
• WEB-INF\
37. Which design pattern did technical designers of JSP use to provide centralized dispatching of requests via a controller servlet?
Answers:
• Model-view-Controller
• Facade
• Server-Client
• Publish-Subscribe
38. Which interface and method name should be used to retrieve HTTP request header information?
Answers:
• HttpServletRequest.getHeaderNames
• ServletRequest.getNames
• ServletRequest.getHeadNames
• None of the above
39. Which interface provides access to request scoped attributes?
Answers:
• ServletContext
• ServletRequest
• ServletConfig
• None of these
40. Which JSP action retrieves the value of a property from a properly declared JavaBean in a JSP page?
Answers:
• jsp:getProperty
• jsp:getParameter
• jsp:getAtrribute
• jsp:getValue
41. Suppose you had a servlet that simply returned an error message because that resource was forbidden to that user. Read the following code snippet:

1.public void service(HttpServletRequestrequest,
2.HttpServletResponseresponse)
3.throws ServletException, IOException
4. {
5.
6. }

What code would you type on line 5 to return an error message to the requesting client?
Answers:
• response.sendError(HTTPServletResponse.SC_FORBIDDEN,"Error");
• response.setStatus(HTTPServletResponse.SC_FORBIDDEN,"Error");
• response.sendError(Response.SC_FORBIDDEN,"Error");
• response.setStatus(SC_FORBIDDEN);
42. With regard to the service() lifecycle method, identify two correct statements about its purpose or about how and when it is invoked.
Answers:
• Upon completion it calls the destroy method
• It is called whenever the servlet is requested
• It is called after the init method is called
• It is only called when the servlet is first requested
43. Which interface and method name should be used to acquire a text stream for the response?
Answers:
• ServletResponse.getOutputStream
• ServletResponse.getWriterStream
• ServletResponse.getTextStream
• ServletResponse.getWriter
44. If cookies are turned off on the client, which two methods still work with the session ID?
Answers:
• response.getSessionId()
• encodeRedirectURL()
• sessionRedirectURL()
• encodeURL()
45. Which among the following objects is the best choice to share information between pages for a single user?
Answers:
• application
• page
• request
• session

No comments:

Post a Comment