Some of what follows is from the Servlet 2.4 specification
doGet() and doPost()
with code to handle http GET and POST requests.
the csc309 servlet context.
References to servlets within that application are via the URL
http://127.0.0.1:8080/csc309
getInitParameter, getInitParameterNames()
setAttribute(), getAttribute(), getAttributeNames(), removeAttributes()
getResource(), getResourceAsStream(), getResourcePaths()
setHeader(), addHeader()
setContentType(), sendRedirect(), sendError()
getWriter() - Obtain a PrintWriter, used to return character data to the client
getParameter(), getParameterNames(), getParameterValues()
getCookies() returns all cookies associated with the request
getSession() returns the Session instance associated with the request (see below)
doGet() and doPost() methods since the original CGILibExample used both the post and get methods
at the same time.
The Hypertext Transfer Protocol (HTTP) is by design a stateless protocol. To build effective web applications, requests from a particular client must be associated with each other. Many strategies for session tracking have evolved over time, but all are difficult or troublesome for the programmer to use directly.
The Servlet API specification defines a simple HttpSession interface that allows a servlet container to use any of several approaches to track a user’s session without involving the Application Developer in the nuances of any one approach.
encodeURL method.
HttpSession session = request.getSession();
// session=current session or newly created one, if none exists
Object o = session.getAttribute("name");
// o=the object associated with "name" in this session
session.setAttribute("name",o);
// o is the object associated with attribute "name" for this session
session.invalidate();
// Invalidates this session then unbinds any objects bound to it.
// NOTE: More than one thread may try to access a session resource.
// The application author is responsible for synchronizing access to
// session resources.
You can download webapps.tar.gz (containing all examples used in this lecture).