首页 > 其他 > 详细

session的用法

时间:2015-08-31 18:55:31      阅读:170      评论:0      收藏:0      [点我收藏+]

原版:http://my.oschina.net/chenhao901007/blog/370109

1.jsp中操作session

(String)request.getSession().getAttribute("username"); // 获取
request.getSession().setAttribute("username""xxx");  // 设置
 
2.java中操作session
//servlet中
request.getSession();
session.getAttribute("username");
session.setAttribute("username""xxx");
session.setMaxInactiveInterval(30*60);
session.invalidate();
  
//struts中方法1
ServletActionContext.getRequest().getSession().setAttribute("username""xxx");
ServletActionContext.getRequest().getSession().getAttribute("username");
ServletActionContext.getRequest().getSession().setMaxInactiveInterval(30*60); 
ServletActionContext.getRequest().getSession().invalidate();
 
//struts中方法2
ActionContext.getContext().getSession().put("username""xxx");
ActionContext.getContext().getSession().get("username");
ActionContext.getContext().getSession().clear();
 
3.web.xml中操作session
<session-config>  
    <session-timeout>30</session-timeout>  
</session-config>
 
4.tomcat-->conf-->conf/web.xml
 
<session-config>
    <session-timeout>30</session-timeout>
</session-config>
 
总结:优先级比较,java中写的要比web.xml中的高。
 
 
 
 
 
 
 
 
 
 
 
 
 
 

session的用法

原文:http://www.cnblogs.com/xiaoxiao5ya/p/4773525.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!