书接上文,我想实现sendRedirect()和getRequestDispatcher()在跳转后是否携带值。
实现的jsp代码:
<%@ page language="java" import="java.util.*" contentType="text/html;charset=gb2312"%>
<html>
<head>
<%--    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>--%>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<form id="r_form" action="${pageContext.request.contextPath}/" method="get" >
    用户名:<input type="text" name="username"/><br/>
    密  码:<input type="password" name="password"/><br/>
    <input type="submit" value="redirect" id="redirect" onclick="check('redirect')">
    <input type="submit" value="request" id="request" onclick="check('request')">
</form>
    <script>
        function check(value) {
            if (value=='redirect'){
          	 document.getElementById("r_form").action="${pageContext.request.contextPath}/redirect";
                } else if (value=='request'){
                document.getElementById("r_form").action="${pageContext.request.contextPath}/request";
            }
        }
    </script>
</body>
</html>