单击单选按钮导航到新JSP

时间:2015-04-06 15:42:25

标签: java jsp

这是我的代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>Select Payment Method<BR><BR>
<font size=""><marquee behavior="alternate">PAYMENT GATEWAY</marquee></font>
<form action="S2ShowPay.jsp" method="post">
        <input type="radio" value="NET BANKING" name="payment" >NET BANKING<br><br>
        <input type="radio" value="DEBIT CARD PAYMENT" name="payment">DEBIT CARD<BR><br>
        <input type="radio" value="CASH ON DELIVERY" name="payment" >CASH ON DELIVERY<br><br>
        <input type="submit" value="NEXT"/>

    </form>
</body>
</html>

当我点击网上银行单选按钮和Debit.jsp时,我只想使用jsp和一些javascript导航到netbanking.jsp。

请帮忙。

2 个答案:

答案 0 :(得分:0)

我不确定你的预期结果是什么,也许你可以尝试一下。如果我错了,请纠正我。

使用location.href

function fnPayment()
{
    if(document.getElementById("a").checked ==true || document.getElementById("b").checked ==true)

    {
        location.href = "http://www.google.com"; //your jsp file
    }
}
</script>

    <input type="radio" value="NET BANKING" name="payment" id="a">NET BANKING<br><br>
    <input type="radio" value="DEBIT CARD PAYMENT" name="payment" id="b">DEBIT CARD<BR><br>
    <input type="radio" value="CASH ON DELIVERY" name="payment" id="c">CASH ON DELIVERY<br><br>

使用响应重定向

由于您已创建S2ShowPay.jsp,因此您可以在单击下一个按钮后将参数传递给它,并根据参数设置响应重定向。

    <input type="radio" value="NET" name="payment" >NET BANKING<br><br>
    <input type="radio" value="DEBIT" name="payment">DEBIT CARD<BR><br>
    <input type="radio" value="CASH" name="payment" >CASH ON DELIVERY<br><br>

S2ShowPay.jsp

String payment_ind = request.getParameter("payment");

if(payment_ind.equals("NET") || payment_ind.equals("DEBIT") )
{
   response.sendRedirect("netbanking.jsp"); 
}

答案 1 :(得分:0)

head代码中添加此代码:

<script type="text/javascript">
function redirectPage(use,rname){
for (var val = 0, r1=use.elements; val < r1.length; val++)
if(r1[val].name==rname&&r1[val].checked)
use.action=r1[val].value;
}
</script>

更改您的form标记,如下所示:

<div>
<form action="#" method="post" onsubmit="redirectPage(this, 'r1');">
<input type="radio" name="r1" value="netbanking.jsp">NET BANKING<br><br>
<input type="radio" name="r1" value="Debit.jsp">DEBIT CARD<BR><br>
<input type="radio" name="r1" value="cashondelivery.jsp">CASH ON DELIVERY<br><br>
<input type="submit" value="Next"/>
</form>
</div>

选择所需的radio按钮,然后点击Next按钮将重定向到相应的页面。