如何实现点击不同的提交按钮,让form表单执行不同的action从而跳转到不同画面


书接上文,我想实现sendRedirect()getRequestDispatcher()在跳转后是否携带值。
我在一个页面内写了两个submit按钮,实现点击不同的按钮后form所携带action的值不同。
实现的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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM