简体   繁体   English

如何在jsp中拉出选定的单选按钮

[英]how to pull selected radio button in a jsp

I have two radio buttons, and depending on which one is selected I want to send them to a specific jsp page.我有两个单选按钮,根据选择的哪个,我想将它们发送到特定的 jsp 页面。 I do not know how to pull which button is selected in my java class.我不知道如何拉出在我的 java 类中选择了哪个按钮。

Here is the jsp:这是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>

here is the java:这是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在servlet中,判断哪个按钮被选中

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. Radio 组返回一个选中的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM