Java servlet-jsp中的会话管理

Java servlet-jsp中的会话管理,java,jsp,servlets,Java,Jsp,Servlets,我目前正在使用servlet和JSP在J2EE中开发一个中级web应用程序。它就像一个内容管理系统。根据我的需要,我的网站的工作方式非常相似,但是关于在J2EE中使用MVC的最佳实践和不良实践存在一些问题 用户登录应用程序的代码为: <c:choose> <c:when test="${not empty sessionScope.admin}"> <a href="/context/controller?action=add-content">

我目前正在使用servlet和JSP在J2EE中开发一个中级web应用程序。它就像一个内容管理系统。根据我的需要,我的网站的工作方式非常相似,但是关于在J2EE中使用MVC的最佳实践和不良实践存在一些问题

用户登录应用程序的代码为:

<c:choose>
    <c:when test="${not empty sessionScope.admin}">
    <a href="/context/controller?action=add-content"> + Add a Content</a>
    </c:when>
    <c:otherwise>
    <a href="/context/controller?action=log-in"> Admin Login</a>
    </c:otherwise>
</c:choose>
要注销,请执行以下操作:

<a href="/context/controller?action=log-out">Logout</a>
我想知道上面的登录、注销和会话管理逻辑是否正确


而且我也无法阻止用户在注销后返回安全页面,我如何设置它?

是!对于简单的web应用程序,此会话管理是正确的!
<a href="/context/controller?action=log-out">Logout</a>
if (action != null && action.equals("log-out")) {
        HttpSession session = request.getSession(false);
        if(session != null){
            session.invalidate();
        }
        request.getRequestDispatcher("index.jsp").forward(
                request, response);
    }