The "session" object represents the conversation between the server and the client. It is used when client information needs to be retained on different JSP pages, such as online shopping and customer Track Tracking.
HTTP is a stateless protocol.
The web server has no historical memory for each client request, and the session is used to save the client information.
Session1.jsp
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<HTML>
<Body>
<Form action = "session2.jsp">
<H1> name:
<Input type = "text" name = "username"> <br>
<Input type = "Submit" value = "Submit">
</Form>
</Body>
</Html>
Session2.jsp
</Head>
<Body>
<%
String name = request. getparameter ("username ");
Session. setattribute ("LOGNAME", name );
%>
<H2> his name "<% = Name %>" has been written into the session </H2>
<Br>
<H1> <a href = 'session3. jsp '> check </a>
</Body>
Session3.jsp
<Body>
<% String yourname = (string) Session. getattribute ("LOGNAME ");
If (yourname = NULL)
{%>
You have not logged on
<%}
Else
{%>
"<% = Yourname %>" logged on
<% }%>
</Body>
The survival range in the session object (as long as the browser is not closed, the session object will always exist). Therefore, in the same browser, no matter how many requests are sent to the server, the session has only one.