如何在HttpSessionListener中获取HttpServletRequest? [英] How can I get HttpServletRequest when in an HttpSessionListener?

查看:136
本文介绍了如何在HttpSessionListener中获取HttpServletRequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从SessionListener访问请求标头?

How can I access request headers from a SessionListener?

我需要在创建当前会话时设置超时。超时需要根据HttpServletRequest中的标头而变化。我已经有一个SessionListener(实现HttpSessionListener)来记录新会话的创建和销毁,它似乎是设置超时的最合理的地方。

I need to set a timeout on the current session when it is created. The timeout needs to vary based on a header in the HttpServletRequest. I already have a SessionListener (implements HttpSessionListener) that logs the creation and destruction of new sessions, and it seems to be the most logical place to set the timeout.

我尝试了以下内容,但它总是将ctx设置为null。

I've tried the following, but it always sets ctx to null.

FacesContext ctx = FacesContext.getCurrentInstance();


推荐答案

HttpSessionListener 无法访问请求,因为在没有请求时调用它—来通知会话销毁。

The HttpSessionListener does not have access to the request because it is invoked when no request has been made—to notify of session destruction.

所以,过滤 Servlet 可以更好地检查请求并指定会话超时。

So, a Filter or Servlet would be better places to examine the request and specify the session timeout.

这篇关于如何在HttpSessionListener中获取HttpServletRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆