会话到期后,如何处理JSP中的异常? [英] How to handle the Exceptions in JSP, when session expires?

查看:70
本文介绍了会话到期后,如何处理JSP中的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究struts1.3.8. JSP页面包含用于迭代会话中数据的脚本.用户打开页面并在会话到期之前不执行任何操作,然后进行下一次刷新,则会抛出java.lang.NullPointerException.

I'm working on struts1.3.8. The JSP page contains scriptlet to iterate the data in the session. Once the user opens the page and not performing any operation till the session expires and then next refreshing it is throwing java.lang.NullPointerException.

那么如何处理该异常以及如何使会话保持活动状态?

So how to handle that exception and how to make the session alive?

推荐答案

您可以依靠会话中知名属性的存在.

You can rely on the existence of a well-known attribute in session.

在首次创建会话时进行设置.

Set this when the session is first created.

session.setAttribute("well-known-attribute", "abcd");

在您的JSP中,执行任何迭代之前,请检查此属性是否存在.

In your JSP, check if this attribute exists before you do any iterations.

if(session.getAttribute("well-known-attribute") != null) {
    // iterate others now
} else {
    session.setAttribute("well-known-attribute", "abcd");
    // now add the other attributes.
}

新会话将总是创建

  • 还没有一个 AND
  • 有一个关联的请求.

这篇关于会话到期后,如何处理JSP中的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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