Servlet Flashcards
GenericServlet implements Servlet interface.
Select one:
a. True
b. False
a. True
How do you write a message back to the browser from inside a Servlet? Select one: a. HttpWriter out = response.getHttpWriter( ) out.println(HTML code) b. BufferedWriter writer = new BufferedWriter(new FileWriter()) writer.write(HTML code) c. PrintWriter out = response.getWriter( ) out.println(HTML code) d. HtmlWriter out = response.get HtmlWriter ( ) out.println(HTML code)
c. PrintWriter out = response.getWriter( ) out.println(HTML code)
How many times are each lifecycle method of a servlet called?
Select one:
a. init once per request, service once per request, destroy once per request
b. init once per request, service once per request, destroy once
c. init once, service once, destroy once
d. init once, service once per request, destroy once
c. init once, service once, destroy once
How would you pre-initialize a servlet? Select one: a. Override the init(ServletConfig config) method b. Override the init( ) method c. You cannot pre-initialize a servlet d. Use the load-on-startup tag
b. Override the init( ) method
True or False. When a servlet throws an exception, the web container searches the configurations in web.xml that use the exception-type element for a match with the thrown exception type.
Select one:
a. True
b. False
a. True
What file is used to map servlet configuration information? Write its full relative path. Select one: a. web.xml b. servlet.xml c. WEB/INF/web.xml d. WEB-INF/web.xml
d. WEB-INF/web.xml
What is not a property of a well-formed XML document?
Select one:
a. All tags should be properly nested
b. Empty tags are necessary to close with a forward slash
c. XML tags are case sensitive
d. Every start tag does not need an end tag
d. Every start tag does not need an end tag
What is the difference between HTTP GET and POST methods?
Select one:
a. GET requests do not remain in the browser history
b. GET requests have no restrictions on data length
c. POST requests cannot be bookmarked
d. GET requests are never cached
c. POST requests cannot be bookmarked
What is the difference between request.getRequestDispatcher forward and response sendRedirect?
Select one:
a. Forward is performed internally by the client
b. Forward is marginally slower than a redirect, since it requires two browser requests, not one
c. With forward, objects placed in the original request scope are not available to the second request
d. Browser is completely unaware that a forward has taken place, so its original URL remains intact
d. Browser is completely unaware that a forward has taken place, so its original URL remains intact
What is the difference between ServletConfig and ServletContext?
Select one:
a. ServletContext object is only available in a Servlet and not a JSP.
b. ServletContext is available to all servlets. ServletConfig is available to only one servlet.
c. ServletConfig is available to all servlets. ServletContext is available to only one servlet.
d. ServletConfig object is only available in a JSP.
b. ServletContext is available to all servlets. ServletConfig is available to only one servlet.
What is the difference between the no-arg init( ) method and the init(ServletConfig config) method?
Select one:
a. Servlets do not have an init( ) method
b. Servlets do not have an init(ServletConfig config) method
c. init(ServletConfig config) is a convenience method meant to be overridden
d. init(ServletConfig config) is called by the Servlet Container to initialize a servlet
d. init(ServletConfig config) is called by the Servlet Container to initialize a servlet
What is the method signature of the doPost method?
Select one:
a. protected void doPost(HttpServletRequest request, HttpServletResponse response)
b. public PrintWriter doPost(HttpServletRequest request)
c. public void doPost(HttpServletRequest request, HttpServletResponse response)
d. protected HttpServletResponse doPost(HttpServletRequest request)
a. protected void doPost(HttpServletRequest request, HttpServletResponse response)
Which code will retrieve all the cookies sent in an HTTP message? Select one: a. request.getSession( ).getCookies( ) b. response.getCookies( ) c. this.getCookies( ) d. request.getCookies( )
d. request.getCookies( )
Which code will store a cookie on the client computer? Select one: a. request.addCookie( ) b. response.addCookie( ) c. this.putCookie( ) d. request.getSession( ).putCookie( )
b. response.addCookie( )
Which is NOT a JSTL core library function? Select one: a. if b. forEach c. choose d. formatNumber
d. formatNumber