gpt4 book ai didi

java - session 超时时重定向到 <错误页面>

转载 作者:行者123 更新时间:2023-12-01 14:15:52 29 4
gpt4 key购买 nike

我有一个在 WebLogic 服务器上运行的标准 J2EE Web 应用程序。我想通过 web.xml 中的元数据设置来处理 session 超时。我尝试使用以下设置

<error-page>
<error-code>408</error-code>
<location>/jsp/testErrorPage.jsp</location>
</error-page>

但是没有成功。

最佳答案

下面是408请求超时的解释,

The Web server (running the Web site) thinks that there has been too long an interval of time between

  1. the establishment of an IP connection (socket) between the client (e.g. your Web browser or our CheckUpDown robot) and the server and
  2. the receipt of any data on that socket, so the server has dropped the connection.

例如,假设您正在尝试登录。但由于某些原因,没有收到任何数据。然后就是408请求超时。

但就您而言,您正在尝试处理 session 超时。这意味着,客户端尚未与服务器建立连接在特定的时间段内(例如 30 分钟)。 表示您在 30 分钟内处于空闲状态,没有进行任何 Activity 。这就是session-timeout的意义。

为了处理 session 超时,您的 web.xml 中必须包含以下代码

<session-config>
<session-timeout>30</session-timeout>
</session-config>

以上代码表明,如果您闲置 30 分钟,您的 session 将被销毁。

此外,您必须编写一个实现 HttpSessionListener 的自定义监听器并将其配置为 listeners在您的 web.xml 中当您的 session 超时时,将执行此代码。您可以尝试在 HttpSessionListener#sessionDestroyed 方法中重定向到错误页面。

如果此解决方案不是您想要的,而是您正在寻找实际解决 408 错误的根本原因,那么 fixing 408 errors页面可能会有所帮助。

关于java - session 超时时重定向到 <错误页面>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18109300/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com