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中的高。

  • 相关阅读:
    c语言之数据类型
    C语言之概述
    012.day12
    011.day011
    010.day010
    010.day08
    010.周六自习
    009.day07
    008.day06
    007.day05
  • 原文地址:https://www.cnblogs.com/chenhao1990/p/4628942.html
Copyright © 2011-2022 走看看