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