java JSF 中的会话超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15856337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:04:18  来源:igfitidea点击:

session-timeout in JSF

javajsfjsf-2session-timeout

提问by Wizard Sultan

I use the following codes to create a session object in JSF. The problem is that after sometime when I am trying to access userdet object it is giving me exception possibly because of session timeout. Is there anyway to increase the session timeout in JSF.

我使用以下代码在 JSF 中创建会话对象。问题是,当我尝试访问 userdet 对象时,它给了我异常可能是因为会话超时。无论如何要增加 JSF 中的会话超时。

            FacesContext context = FacesContext.getCurrentInstance();
            HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
            session.setAttribute("userdet",user);

When I use servlet I use the following codes but is it applicable to JSF also?

当我使用 servlet 时,我使用以下代码,但它也适用于 JSF 吗?

<web-app ...>
    <session-config>
        <session-timeout>20</session-timeout>
    </session-config>
</web-app>

回答by dcernahoschi

Yes. Session timeout for JSF applications is set in web.xml too.

是的。JSF 应用程序的会话超时也在 web.xml 中设置。

In fact JSF makes use of Java Servlets to handle http requests and responses.

事实上,JSF 使用 Java Servlets 来处理 http 请求和响应。

回答by EdH

As dcernahoschi states, the web.xml will define the session timeout for JSF.

正如dcernahoschi 所述,web.xml 将定义JSF 的会话超时。

This can also be set programmatically via the HttpSession as well, using the setMaxInactiveInterval method.

这也可以通过 HttpSession 以编程方式设置,使用 setMaxInactiveInterval 方法。