Home Database Mysql Tutorial JSP由浅入深(9)―― JSP Sessions_MySQL

JSP由浅入深(9)―― JSP Sessions_MySQL

Jun 01, 2016 pm 02:08 PM
session different keep name Browser user net

在经典的网站上,访问者可以浏览几个网页并执行一些交互的行为。如果你在编写这样的网站,利用每一个用户的一些数据是非常有用的。为了这个目的,我们可以使用JSP中的"sessions"。

Session是一个跟用户相关的对象。当用户访问网站的时候,一些数据就被存放于session中,并在需要的时候从中取出数据。Session为不同的用户保存了不同了数据。

以下的网页将用户的名字放置于session中,并可以在其它地方来显示它。首先我们要制作一个表单,然后将它命名为GetName.html







What's your name?









这个表单的目标是“SaveName.jsp”,它在session保存了用户的名字。


String name = request.getParameter( "username" );

session.setAttribute( "theName", name );

%>





Continue





SaveName.jsp在session保存了用户了名字,并连接到另外一个网页NextPage.jsp。NextPage.jsp 显示了怎样取出被保存的名字:





Hello,





如果你打开两种不同的浏览器,或者从两台不同的机器上运行两个浏览器,你可以在一个浏览器中放置一个名字,而在另外一个浏览器中放置另外的名字,但是两个名字都将被跟踪。Session保持跟踪直到超时,这时它就会假设用户没有访问网站了,所以就取消了session。

最后再布置一下本教程的联系:利用session,在上面的例子中增加一个用户的“age”属性。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The width of emsp spaces in HTML is inconsistent. How to reliably implement text indentation? The width of emsp spaces in HTML is inconsistent. How to reliably implement text indentation? Apr 04, 2025 pm 11:57 PM

Regarding the problem of inconsistent width of emsp spaces in HTML and Chinese characters in many web tutorials, it is mentioned that occupying the width of a Chinese character, but the actual situation is not...

How to achieve gap effect on the card and coupon layout with gradient background? How to achieve gap effect on the card and coupon layout with gradient background? Apr 05, 2025 am 07:48 AM

Realize the gap effect of card coupon layout. When designing card coupon layout, you often encounter the need to add gaps on card coupons, especially when the background is gradient...

How to use the clip-path attribute of CSS to achieve the 45-degree curve effect of segmenter? How to use the clip-path attribute of CSS to achieve the 45-degree curve effect of segmenter? Apr 04, 2025 pm 11:45 PM

How to achieve the 45-degree curve effect of segmenter? In the process of implementing the segmenter, how to make the right border turn into a 45-degree curve when clicking the left button, and the point...

How to select and style elements of the first specific class using CSS and JavaScript? How to select and style elements of the first specific class using CSS and JavaScript? Apr 04, 2025 pm 11:33 PM

How to select and style elements of the first specific class using CSS and JavaScript? In web development, you often encounter the need to select and modify specific classes...

How to obtain real-time application and viewer data on the 58.com work page? How to obtain real-time application and viewer data on the 58.com work page? Apr 05, 2025 am 08:06 AM

How to obtain dynamic data of 58.com work page while crawling? When crawling a work page of 58.com using crawler tools, you may encounter this...

Vue2 project online iframe white screen: How to troubleshoot and solve it? Vue2 project online iframe white screen: How to troubleshoot and solve it? Apr 05, 2025 am 06:21 AM

Troubleshooting and solving the online white screen of iframe in Vue2 project. In the development of Vue2 project, we often use iframes to embed other web content. However, the item...

How to achieve the gradient effect of CSS fonts? How to achieve the gradient effect of CSS fonts? Apr 04, 2025 pm 10:12 PM

Implementing the CSS font gradient effect Many developers hope to achieve cool font gradient effect on web pages. This article will explain in detail how to use CSS3 to implement the graph...

How to distinguish between closing a browser tab and closing the entire browser using JavaScript? How to distinguish between closing a browser tab and closing the entire browser using JavaScript? Apr 04, 2025 pm 10:21 PM

How to distinguish between closing tabs and closing entire browser using JavaScript on your browser? During the daily use of the browser, users may...

See all articles