【发布时间】:2011-02-22 01:03:03
【问题描述】:
我有一个 JSP/Servlet Web 应用程序,它包含多个 servlet(和一些 JSP)
每当用户访问 servlet A 时,我都需要创建一个新的 HttpSession,因为知道 servlet A 是主页(即,他将其作为应用程序中的第一个 servlet/页面访问)。
到目前为止一切顺利,我可以在 servlet A 的开头编写以下代码:
HttpSession session = request.getSession(false);
if (session == null) {
logger.debug("starting new session...");
session = request.getSession();
// other stuff here
}
但问题是,如果用户没有关闭他的浏览器(即使他关闭了选项卡 - 例如在 Firefox 中 - 会话仍将打开),所以当他尝试再次打开我的网站时,最后会话将被重新使用(当然在会话超时的范围内),我不需要这个。我需要每当他访问 Servlet A 时,他都会获得一个全新的 HttpSession。
但不幸的是,根据某些场景,他可能会在每个会话中访问此 servlet 两次!
【问题讨论】: