save username in session and then retrieve username from session
2012-01-24 01:54
525 查看
<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 target of the form is "SaveName.jsp", which saves the user's name in the session. Note the variable "session". This is another variable that is normally made available in JSPs, just like out and requestvariables. (In the @page directive, you can indicate that you do not need sessions, in which case the "session" variable will not be made available.)
<% String name = request.getParameter( "username" ); session.setAttribute( "theName", name ); %> <HTML> <BODY> <A HREF="NextPage.jsp">Continue</A> </BODY> </HTML>
The SaveName.jsp saves the user's name in the session, and puts a link to another page, NextPage.jsp.
NextPage.jsp shows how to retrieve the saved name.
<HTML> <BODY> Hello, <%= session.getAttribute( "theName" ) %> </BODY> </HTML>
相关文章推荐
- WWDC 2017 Session笔记 - Session 708 推送消息新功能和最佳实践(Best Practices and What’s New in User Notifications)
- Disable to auto complete fill in user name and password
- [Ubuntu] Simple method to login SSH without insert user name and password via expect in linux
- Save picture as XML and retrieve pic from xml file
- How to create a project from existing source in Eclipse and then find it?
- Retrieve data from xml and show in listField
- 从2009年至2014年脸书(Facebook)的用户行为及其发展 The User Behavior in Facebook and its Development from 2009 until
- [Angular & Web] Retrieve user data from Session
- select * from user where name in (select name from user group by name having count(*) > 1)
- 关于错误信息【schedMgr: Error processing calendar profile document(NoteID: *) in database mail/*.nsf: Cannot find user in Name and Addr
- MySQL查询优化:LIMIT 1避免全表扫描【如判断用户是否存在select * from users where username='123' and passwd='123' limit 1】
- Get File Name from File Path in Python | Code Comments
- LeetCode(Construct Binary Tree from Preorder and Inorder Traversal )根据二叉树的中序遍历和后序遍历重建二叉树
- Error creating bean with name 'sessionFactory' defined in ServletContext resource 解决方法之一
- change Username for SVN(Subclipse) in Eclipse
- SharePoint2010:从用户控件中打开文档 -Open document(s) in Office web apps (from User controls)
- LeetCode - Construct Binary Tree from Inorder and Postorder Traversal
- 微信接收消息与返回给微信的消息中的tousername、fromusername的值
- 【LeetCode-面试算法经典-Java实现】【105-Construct Binary Tree from Preorder and Inorder Traversal(构造二叉树)】
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code