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介面,然後在轉到登入介面,就可以實現跳轉併到父級別框架中。