frameset跳转问题

frameset跳转出现问题一般都是注销后页面显示多个或者账户过期后点击功能跳转到登录界面多个窗口显示。
以下是给出的例子:

第一种情况是:点击注销按钮的问题解决方式就是使用js调用父窗口请求后台,后台处理后重定向到login.sp,如下:
页面a和js
<a onclick="managerout()" " >注销</a>

function managerout()
{
 window.parent.location.href = "${pageContext.request.contextPath }/managerout.action";
}

控制器

public String managerout(HttpSession session){
        session.removeAttribute("manageruser");
        return "redirect:/login.jsp";
    }

这样就解决了注销跳转问题。

第二种情况是账号过期了,点击管理页面请求后自动让其重新登录。

这种情况可以使用过滤器进行实现,当session中的账号信息取出来是空的时候,就先转发到一个jsp然后那个jsp进行跳转到login.jsp。
过滤器

public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
            throws IOException, ServletException {
        // TODO Auto-generated method stub
        HttpServletRequest req=(HttpServletRequest) arg0;
        HttpServletResponse res=(HttpServletResponse) arg1;
        //获得session中的对象
        HttpSession session= req.getSession();
        manager manageruser=(manager) session.getAttribute("manageruser");
        if(manageruser!=null){
        arg2.doFilter(arg0, arg1);
        }else{
        req.setAttribute("messagemsg","您没有登录或者账号密码已过期,请重新登录!!!");//提示信息
        req.setAttribute("messageurl","2;URL=/test/login.jsp");//这句是将跳转到页面2秒后跳转到login.jsp
        req.getRequestDispatcher("/message.jsp").forward(req, res);
        }
    }

message.jsp页面

<body>
    <center>
        <h2>
            <%String messagemsg=(String)request.getAttribute("messagemsg"); 
              String messageurl=(String)request.getAttribute("messageurl");
            %>
            <a><%=messagemsg%></a>
            <%
                response.setHeader("refresh", messageurl);//这里是你要确定的时间秒URL是要跳转的地址
            %>
        </h2>
        <p>页面将在两秒秒后跳回。。。</p>
    </center>
  </body>

这就解决了账户过期后页面跳转的问题。

发布了64 篇原创文章 · 获赞 103 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/P_Doraemon/article/details/81026396
今日推荐