在APC中使用Session 的修正

博主因考虑不周,导致session工具类出错,现分享修正后的代码。代码包含获取session、获取属性、设置属性和设置超时时间等方法,涉及javax.servlet.http.HttpSession等相关类的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于本人欠考虑,导致使用session的工具类出现错误,在此将修正的代码重贴(在此表示歉意):
package com.fujitsu.eFrame.eftool;
 
import javax.servlet.http.HttpSession;
 
import com.fujitsu.uji.DispatchContext;
import com.fujitsu.uji.http.HttpSessionProfile;
 
public class SessionUtil {
 
       private static HttpSession getSession(DispatchContext context) {
         
              return ((HttpSessionProfile)context.getSessionProfile()).getSession();
         
       }
       
       public static Object getAttribute(DispatchContext context, String name) {
         
              try {
                return getSession(context).getAttribute(name);
              } catch (IllegalStateException ex){
                return null;
              }
         
       }
       
       public static void setAttribute(DispatchContext context, String name, Object value) {
         
              getSession(context).setAttribute(name, value);
         
       }
       
       public static void setTimeout(DispatchContext context, int seconds) {
         
              getSession(context).setMaxInactiveInterval(seconds);
         
       }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值