jsp的表单跳转到servlet后跳转回jsp到父级框架

问题:在修改密码后登出,用新密码重新登录。

    在servlet里判断

    .)如果修改密码成功就登出并跳转到登录界面(跳转到父级框架)

    .)失败就退回修改密码的界面(在原框架跳转)

    如果在表单提交时增加taget属性会导致两种结果就跳转到指定的框架,无法区分。

解决:需要在servlet跳转到父级页面的步骤之间,增加一个onload.jsp页面用来重新选择跳转的框架

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%  
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
%>  
  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
    <base href="<%=basePath%>">  
      
    <title>test page</title>  
      
    <meta http-equiv="pragma" content="no-cache">  
    <meta http-equiv="cache-control" content="no-cache">  
    <meta http-equiv="expires" content="0">      
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
    <meta http-equiv="description" content="This is my page">  
    <script>  
        function load(){  
            parent.location.href="${pageContext.request.contextPath }/admin/login.jsp"  
        }  
    </script>  
  
  </head>  
  <body onload="load()">  
  </body>  

</html>


核心代码:  parent.location.href="${pageContext.request.contextPath }/admin/login.jsp"  

说明:servlet先定向到onload.jsp界面,然后在转到登录界面,就可以实现跳转并到父级别框架中。

猜你喜欢

转载自blog.csdn.net/wyf871125/article/details/80331947