JSP由浅入深(9)―― JSP Sessions_MySQL
在经典的网站上,访问者可以浏览几个网页并执行一些交互的行为。如果你在编写这样的网站,利用每一个用户的一些数据是非常有用的。为了这个目的,我们可以使用JSP中的"sessions"。
Session是一个跟用户相关的对象。当用户访问网站的时候,一些数据就被存放于session中,并在需要的时候从中取出数据。Session为不同的用户保存了不同了数据。
以下的网页将用户的名字放置于session中,并可以在其它地方来显示它。首先我们要制作一个表单,然后将它命名为GetName.html
这个表单的目标是“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”属性。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The steps to register an Ouyi account are as follows: 1. Prepare a valid email or mobile phone number and stabilize the network. 2. Visit Ouyi’s official website. 3. Enter the registration page. 4. Select email or mobile phone number to register and fill in the information. 5. Obtain and fill in the verification code. 6. Agree to the user agreement. 7. Complete registration and log in, carry out KYC and set up security measures.

The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

To safely download the Binance APP, you need to go through the official channels: 1. Visit the Binance official website, 2. Find and click the APP download portal, 3. Choose to scan the QR code, app store, or directly download the APK file to download to ensure that the link and developer information are authentic, and enable two-factor verification to protect the security of the account.

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Choose a reliable trading platform such as OKEx to ensure access to the official entrance.

Registering a Sesame Door Account requires 7 steps: 1. Prepare a valid email or mobile phone number and a stable network; 2. Visit the official website; 3. Enter the registration page; 4. Select and fill in the registration method; 5. Obtain and fill in the verification code; 6. Agree to the user agreement; 7. Complete registration and log in, it is recommended to carry out KYC and set security measures.

EU MiCA compliance certification, covering 50 fiat currency channels, cold storage ratio 95%, and zero security incident records. The US SEC licensed platform has convenient direct purchase of fiat currency, a ratio of 98% cold storage, institutional-level liquidity, supports large-scale OTC and custom orders, and multi-level clearing protection.

Visit Binance official website and check HTTPS and green lock logos to avoid phishing websites, and official applications can also be accessed safely.
