zoukankan      html  css  js  c++  java
  • iframe和response.sendRedirect()跳转到父页面的问题

    在项目中,因为为了给页面分层次,就使用了 内嵌iframe 的分了三个框。在子页面进行操作的时候,如果session超时,就要被拦截器拦截重新回到首页进行登录,但是在sub页

    面 ,进行操作的时候,如果session超时,需要跳转到首页进行登录的话,首页的页面就嵌在sub页面进行显示 了,这样显然是不符合逻辑了,应该是跳回到最顶层的父页面.

    错误的代码如下:

    HttpSession session = request.getSession();
    		Object obj = session.getAttribute(Constant.LOGIN_USER);
    		if (obj == null) {
    			response.sendRedirect(request.getContextPath() + "/index.jsp");
    			return false;}
    

      因为response.sendRedirect()没有target属性,但html页面和js中有,于是,当判断出用户没有访问权限时,我们可以在jsp中使用js来转向到真正的登录页面。

    正确跳转到父页面的代码:

    	HttpSession session = request.getSession();
    		Object obj = session.getAttribute(Constant.LOGIN_USER);
    		if (obj == null) {
    		    PrintWriter out = response.getWriter();
    		    out.println("<html>");    
    		    out.println("<script>");    
    		    out.println("window.open ('"+request.getContextPath()+"/index.html','_top')");    
    		    out.println("</script>");    
    		    out.println("</html>");  
    			return false;
    		}
    

      

  • 相关阅读:
    搜狗五笔快捷键
    [原抄] Potplayer 1.7.2710 快捷键
    权限设置并未向在应用程序容器 不可用
    fork( )函数(转载)
    软件开发中的迭代(转载)
    进程间通信的方式(转载)
    P NP NPC(1)(转载)
    P NP NPC(2)(转载)
    大小端字节序
    求n对括号的排列组合(卡特兰数)
  • 原文地址:https://www.cnblogs.com/tianlong/p/10336789.html
Copyright © 2011-2022 走看看