HttpSession
来源:互联网 发布:淘宝网佛经早晚课读本 编辑:程序博客网 时间:2024/05/16 05:31
The HttpSession
object represents a user session. A user session contains information about the user across multiple HTTP requests.
When a user enters your site for the first time, the user is given a unique ID to identify his session by. This ID is typically stored in a cookie or in a request parameter.
Here is how you access the session object:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession();}
You can store values in the session object, and retrieve them later. First, let’s see how you can store values in the session object:
session.setAttribute("userName", "theUserName");
This code sets an attribute named “userName
“, with the value “theUserName
“.
To read the value again, you do this:
String userName = (String) session.getAttribute("userName");
Values stored in the session object are stored in the memory of the servlet container.
Sessions and Clusters
If you have an architecture with 2 web servers in a cluster, keep in mind that values stored in the session object of one server, may not be available in the session object on the other server. So, if a user’s requests are divided evenly between the two servers, sometimes session values may be missing.
The solution to this problem would be one of:
- Do not use session attributes.
- Use a session database, into which session attributes are written, and from which it is read.
- Use sticky session, where a user is always sent to the same server, throughout the whole session.
- HttpSession
- HttpSession
- HttpSession
- httpsession
- HttpSession
- HttpSession
- HttpSession
- HttpSession
- HttpSession
- HTTPSession
- HttpSession
- HttpSession
- HttpSession
- HttpSession
- HttpSession
- HttpSession
- HttpSession
- HttpSession
- 自定义adapter的基础上Listview优化方案以及几个小错误(checkbox吃掉点击事件以及对象重复问题)
- APK反编译二次打包工具和方法
- 数组知识点
- STL源码剖析 [容器](十二)[RB_Tree]
- 深入浅出CChart 每日一课——快乐高四第十二课 必也正名,Win32标准控件ChartCtrl之初识
- HttpSession
- C99标准支持结构体按成员名称进行指定初始化。
- .NET程序的性能要领和优化建议
- 自定义Adapter的listview(很重要)
- a different object with the same identifier value was already associated with the session:
- java常用API知识点总结
- 解决maven项目update project更改项目编码的问题
- Android Drawable系列(1):自定义背景以及注意事项
- Codeforces 574B Bear and Three Musketeers