我有两个单选按钮,具体取决于选择哪一个我想要将它们发送到特定的JSP页面。我不知道如何在我的Java类中选择哪个按钮。

这是JSP:

<form method="post" action="ttp.actions.Sale1Action.action">

        <input type="radio" name="radio1" value="packages"checked> packages<br>
        <input type="radio" name="radio1" value="productions"> productions<br>

    <input type="submit" value="  next  "/>

</form>
.

这是java:

public class Sale2Action implements Action {

    public String process(HttpServletRequest request, HttpServletResponse response) throws Exception {


        String prodPack = request.getParameter("radio1");
        System.out.println("radio1 = " + prodPack);
        String venueID = request.getParameter("venueid");
        Venue v = VenueDAO.getInstance().read(venueID);


        if (prodPack.equals("packages")) {
            return "sale3a.jsp";
        } else {
            return "sale3b.jsp";
        }
    }
}
.

有帮助吗?

解决方案

In the servlet, to determine which button is selected

String value = request.getParameter("radio1"); 

You will get the value. If you check packages, the value will be "packages". Radio group return one checked value.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top