java—如何在jsp中拉取选定的单选按钮

omvjsjqw  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(391)

我有两个单选按钮,根据选择的单选按钮,我希望将它们发送到特定的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";
        }
    }
}
sd2nnvve

sd2nnvve1#

在servlet中,确定选择了哪个按钮

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

你会得到价值。如果检查包,则值将为“packages”。无线组返回一个选中值。

相关问题