how to pull selected radio button in a jsp

让人想犯罪 __ 提交于 2021-02-16 20:18:19

问题


I have two radio buttons, and depending on which one is selected I want to send them to a specific jsp page. I do not know how to pull which button is selected in my java class.

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

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";
        }
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/5478959/how-to-pull-selected-radio-button-in-a-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!