跳轉方式: window.location.href
參數傳遞方式:URL
JSP1代碼:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<script>
function go() {
//獲取#dia的值
var s = document.getElementById("dia").innerHTML;
console.log(s);
//實現頁面之間的跳轉和URL傳遞參數
window.location.href = "index2.jsp?s="+s;
}
</script>
</head>
<body>
<div>
<p id="dia">pass me</p>
<button type="button" onclick="go();">click me</button>
</div>
</body>
</html>
JSP2代碼:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
//接收URL傳遞來的參數
String flowid = request.getParameter("s");
%>
<html>
<head>
<title>Title</title>
</head>
<body>
<p>使用wind.location.href跳轉成功</p>
//將參數顯示到頁面上
<p>取得值為:<%=flowid%></p>
</body>
</html>
僅供復習知識點參考
