CIT 597 Quiz 6: Servlets and JSP
Fall 2008, David Matuszek Name_________________________________________
  1. (10 points) List two differences between a servlet and a CGI script.
    Servlets stay in memory, so don't have to be reloaded.
    Servlets don't quit after each response.
    One servlet can handle multiple requests.
    Servlets can be run in a sandbox.
    Servlets must be in Java.

  2. (6 points) The service method takes two parameters. What are the types of those parameters?
    HttpServletRequest and HttpServletResponse

  3. (4 points) Tell one limitation of sending a request with GET (as opposed to POST).
    The length of the request is limited by the allowed length of the URL.

  4. (5 points) If either GET or POST will work for you, how should you decide which to use?
    doGet should just request data; it should not change anything on the server (it should be "idempotent")
    doPost should be used when the server should be affected (remember something, take some action)


  5. (5 points) What is the single most important purpose of the Deployment Descriptor?
    To tell the server where to find the servlet.

  6. (5 points) What must a servlet or JSP do before using the PrintWriter to write out the HTML page?
    Set the mime type.


  7. (5 points) What must the XML Deployment Descriptor file be named?         web.xml

  8. (5 points) When the Java Session Tracking API starts a new session, it sends a cookie and does session rewriting. What does it do on the next request from the same session?

    If it receives a cookie, it abandons URL rewriting.


  9. (15 points) Name three predefined variables in JSP.

    request, response, session, out

  10. (20 points) What are the four types of JSP "tags"? Give the syntax, including what kind of thing (expression, etc.) should be in each tag.
    <%= expression %>
    <% code %>
    <%! declarations %>
    <%@ directive attribute="value" %>
  11. (5 points) What distinction do servlets make between parameters and attributes?
    Parameters are considered to be read-only.

  12. (15 points) Name (or tell what object holds) each of the three servlet scopes.
    Application scope (ServletContext object)
    Session scope (HttpSession object)
    Request scope (ServletRequest object)