JSP built-in object (Session)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.