java web中session简单的使用

1.jsp中操作session

1(String)request.getSession().getAttribute("username"); // 获取 2request.getSession().setAttribute("username", "xxx");  // 设置

2.java中操作session

1//servlet中 2request.getSession(); 3session.getAttribute("username"); 4session.setAttribute("username", "xxx"); 5session.setMaxInactiveInterval(30*60); 6session.invalidate(); 7  8//struts中方法1 9ServletActionContext.getRequest().getSession().setAttribute("username", "xxx"); 10ServletActionContext.getRequest().getSession().getAttribute("username"); 11ServletActionContext.getRequest().getSession().setMaxInactiveInterval(30*60);  12ServletActionContext.getRequest().getSession().invalidate(); 13 14//struts中方法2 15ActionContext.getContext().getSession().put("username", "xxx"); 16ActionContext.getContext().getSession().get("username"); 17ActionContext.getContext().getSession().clear();

3.web.xml中操作session

1<session-config>   2    <session-timeout>30</session-timeout>   3</session-config>

4.tomcat-->conf-->conf/web.xml

1<session-config> 2    <session-timeout>30</session-timeout> 3</session-config>

总结:优先级比较,java中写的要比web.xml中的高。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

sourceTree 添加 ssh key 方法

1.使用git客户的生成公私钥:id\rsa、id\rsa.pub1.1设置Git的username和email:$gitconfigglobaluser.name"xxx"$gitconfig\globaluser.email"xxx.mail@xxx.com"1.2.生成SSH密钥过程:1.2.1.检查是不是已经存在密钥(

Java日期时间API系列31

  时间戳是指格林威治时间1970年01月01日00时00分00秒起至现在的总毫秒数,是所有时间的基础,其他时间可以通过时间戳转换得到。Java中本来已经有相关获取时间戳的方法,Java8后增加新的类Instant等专用于处理时间戳问题。 1获取时间戳的方法和性能对比1.1获取时间戳方法Java8以前