Js|session on a classic website, visitors can browse several Web pages and perform some interactive behavior. If you are writing such a website, it is very useful to use some data from each user. For this purpose, we can use the "sessions" in the JSP.
Session is a user-related object. When a user visits a Web site, some data is stored in the session and extracted from the data when needed. The session saves different data for different users.
The following page places the user's name in the session and can display it elsewhere. First we're going to make a form and then name it getname.html
<HTML>
<BODY>
<form method=post action= "savename.jsp" >
What ' s your name? <input Type=text Name=username size=20>
<p><input type=submit>
</FORM>
</BODY>
</HTML>
The goal of this form is "savename.jsp", which saves the user's name in session.
<%
String name = Request.getparameter ("username");
Session.setattribute ("Thename", name);
%>
<HTML>
<BODY>
<a href= "nextpage.jsp" >Continue</A>
</BODY>
</HTML>
Savename.jsp saves the user's name in session and connects to another page nextpage.jsp. Nextpage.jsp shows how to remove the saved name:
<HTML>
<BODY>
Hello, <%= session.getattribute ("thename")%>
</BODY>
</HTML>
If you open two different browsers, or run two browsers from two different machines, you can place a name in one browser and a different name in the other browser, but two names will be tracked. The session remains tracked until it times out, and it assumes that the user has not visited the site, so it is canceled.
Finally, decorate this tutorial with the link: Use session, in the above example to add a user's "age" attribute.
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.