CIT597 Quiz 5 (Servlets)
Fall, 2007
Name_________________________________________

Please keep all answers short and to the point. Read each question and answer it; don't add information that wasn't asked for.

  1. (10 points) List two important differences between servlets and CGI scripts.
    Running a servlet doesn’t require creating a separate process each time
    A servlet stays in memory, so it doesn’t have to be reloaded each time
    One instance handles multiple requests, not a separate instance for every request
    Untrusted servlets can be run in a “sandbox”

    Servlets must be in Java; CGI scripts can be in any language
  2. In an HttpServlet ,
    1. (8 points) What are the names of the two methods you are most likely to override?

      doGet and doPost

    2. (4 points) What are the parameter types required by these two methods?

      HttpServletRequest and HttpServletResponse

  3. (12 points) Each servlet has three names. Briefly, what are those names?

    The “real” name, given to it by the programmer
    An “internal” name, used only within the web.xml file
    The name that the user (client) knows it by


  4. (5 points) Tomcat requires the Deployment Descriptor file to have a certain name. What is that name?

    web.xml

  5. (12 points) If you don't use Java's Session Tracking API, list the three techniques you can use to keep track of a session ID.

    Hidden <form> fields, cookies, and URL rewriting

  6. (5 points) What session tracking technique does Java's Session Tracking API use when starting a new session?

    It both sends a cookie and does URL rewriting



  7. (6 points) When using Java's Session Tracking API, how do you get a session? Specify both the object that you ask for the session and the message you send to it.

    HttpSession session = request.getSession();


  8. (12 points) Tell what goes inside each of the following JSP constructs.

    1. <%= expression %>

    2. <% code, statements %>

    3. <%! declarations %>

  9. (9 points) Name the three scopes that can be accessed by a servlet.

    Application scope, Session scope, and Request scope

  10. (4 points) What is the distinction between a parameter and an attribute?

    Parameters are read-only

  11. (4 points) In what object does the servlet communicate its results to the JSP?

    In the HttpServletRequest object

  12. (3 points) Name one place that a servlet can keep information that is thread-safe.

    Local variables
    In the HttpServletRequest object (or the HttpServletResponse object)


  13. (6 points) In class I listed three advantages of using MVC. Mention two of them.

    Separation of concerns, flexibility, reusability