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

  • 相关阅读:
    数据查询
    泰勒展开及其应用
    搜索排序算法
    因子分解机 FM
    偏差方差分解
    Softmax 损失-梯度计算
    目标检测网络之 Mask R-CNN
    目标检测网络之 R-FCN
    深度学习-conv卷积
    目标检测网络之 YOLOv3
  • 原文地址:https://www.cnblogs.com/chenhao1990/p/4628942.html
Copyright © 2011-2022 走看看