【问题标题】:Redirection to home page [closed]重定向到主页[关闭]
【发布时间】:2015-08-21 06:40:24
【问题描述】:

在创建登录页面的jsp页面中,它包含用户名和密码字段,将用户名存储在会话中,并正在验证字段,如果一切正确,它将被重定向到主页 ( home.jsp).

这一切都成功发生了。

我的问题是,当我输入登录页面的 url 时,它带有 localhost:2500/shashi/login.jsp url。

当它被重定向到主页时,url 将是 localhost:2500/shashi/home.jsp。它是正确的。

但是假设登录后,如果会话没有过期,

如果我输入 localhost:2500/shashi/login.jsp 登录 url,它应该重定向到 homelocalhost:2500/shashi/home.jsp

我如何做到这一点? java是服务器端代码。网络服务器码头

【问题讨论】:

标签: java .htaccess jsp redirect


【解决方案1】:

我想到了这样简单的事情:

if(request.getSession(false).getAttribute("username") == null){
    response.sendRedirect("/home.jsp");
}

【讨论】:

    【解决方案2】:
    <%  if(request.getSession(false).getAttribute("username") == null) {
    
            %>
            <script type="text/javascript">
                window.location="${pageContext.request.contextPath}/home";
            </script>
            <%          
        }
    %>
    

    尝试在您的 header.jsp 文件中插入此代码,如果头文件不存在则放入 jsp 文件中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多