<< Chapter < Page Chapter >> Page >

Missing Figure

Figure 3 - Output from access #3.

Missing Figure

Figure 4 - Output from access #4.

Missing Figure

Figure 5 - Output from access #5.

Missing Figure

Figure 6 - Output from access #6.

Missing Figure

Figure 7 - Output from access #7.

Missing Figure

The HttpSession Interface

I will explain the code in this servlet in fragments. A complete listing of the servlet is provided in Listing 10 .

Beginning of the doGet method

Listing 1 shows typical code for beginning the definition of a servlet class and for beginning the definition of the doGet method. You have seen code like this in earlier modules so I won't discuss it further inthis module.

Listing 1 - Beginning of the doGet method.
import java.io.*; import java.util.*;import javax.servlet.*; import javax.servlet.http.*;public class Java4580a extends HttpServlet{public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{

Get the session object

I will continue the discussion with the code fragment shown in Listing 2 , where request is a reference to the standard object of type HttpServletRequest passed to the doGet method that begins in Listing 1 .

Listing 2 - Get the session object.
HttpSession session = request.getSession(true);

An object of type HttpSession

The call to the getSession method in Listing 2 returns a reference to an object of the interface type HttpSession . As you can see, the reference is saved in the local variable named session .

The HttpSession object provides an association (a session) between an HTTP client and an HTTP server. This association, or session, persists over multiple connectionsand/or requests during a given time period. Sessions are used to maintain state and user identity across multiple page requests.

How is the session maintained?

Apparently the manner in which the association between the client and the server (the session) is maintained varies from one server to the next. One books states,

"A session can be maintained either by using cookies or by URL rewriting."

Another book states that the minimum requirement for servers is to maintain the session using cookies, andthat the server may optionally support URL rewriting as well. There are inferences in other books to the effect that some servers may not supportURL rewriting.

The HttpSession object

The HttpSession object returned by the code in Listing 2 behaves as a container for the storage of:

  • Information about the session
  • Data (objects) that persist from one call to the servlet to the next call to the servlet by the same client.

Client ID is transparent

The requirement to maintain the identification of each individual client is transparent to the programmer. That information is encapsulated in the HttpSession object and the process that backs it up.

The lifetime of a session

An HttpSession object represents an ongoing session with a particular client. The actual lifetime of a session isn't clear in the booksthat I have read.

The books seems to imply that the session can remain active over long periods of time. However, on my local Tomcat server, thesession ends when the browser is terminated. The behavior is similar to that which occurs with the default behavior of cookies that expire when the browser exits.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask