2個JSP頁面傳遞參數


跳轉方式: 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>
View Code

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>
View Code

僅供復習知識點參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM