zoukankan      html  css  js  c++  java
  • JavaEE中对Session操作

    jsp中:

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

    Java中:

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

    web.xml中:

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

    tomcat-->conf-->conf/web.xml中:

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

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

  • 相关阅读:
    5.21 CSS样式表练习
    5.20 c#验证码练习
    5.20 邮箱注册,及网页嵌套,知识点复习
    5.19 网页注册练习
    5.19练习标签及其 定义
    5.16 兔子生兔子,日期时间练习
    5.15 复习;共5题
    5.11 集合 与 特殊集合
    5.11 集合与特殊集合
    WinForm1
  • 原文地址:https://www.cnblogs.com/chenhao1990/p/4628942.html
Copyright © 2011-2022 走看看