Java Reference
In-Depth Information
2. Enter lines 76 through 88 as shown in Figure 12-19.
TextPad displays the doPost() method for the servlet (Figure 12-21). Each
thread has a unique copy of local variables, unlike instance variables, which
are shared by threads.
setContentType() method
specifies MIME type
local variables
doPost() method
getWriter()
method returns
PrintWriter
object used to
send output to
Web browser on
client machine
FIGURE 12-21
Because both the doGet() and doPost() methods are to be treated alike, the
doGet() method in lines 70 through 74 calls the doPost() method, which starts
in line 76, rather than duplicating the same code.
Implementing Session Tracking with HTTP
Recall that Web browsers and Web servers communicate with each other
using HTTP. HTTP is a stateless protocol , meaning that it does not maintain
state; that is, it does not provide a means of maintaining information about a
connection between requests. A session is a series of requests from the same
user. The Web server cannot determine that a request from a browser belongs
to the same session as a previous request.
Session tracking provides a way to identify a user across more than one
request and, optionally, to store persistent information about the user between
those requests. Through the servlet API, Java provides a mechanism for HTTP
session tracking by creating a session object of type HttpSession, which has a
unique identifier. A session object models the user session and is created by the
servlet container when the browser makes its first request to a site. A session may
time out if the time between client accesses exceeds some maximum; a session
timeout means that the maximum interval between accesses was exceeded, and
the server invalidated the session. Session timeouts often are set to 30 minutes
between accesses, although they can vary by server or by application. A servlet
also can invalidate a session explicitly, if needed.
 
Search WWH ::




Custom Search