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

仅供复习知识点参考

posted @ 2017-05-19 16:16  Dia  阅读(4120)  评论(0编辑  收藏  举报