java 如何在jsp中拉出选定的单选按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5478959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to pull selected radio button in a jsp
提问by novicePrgrmr
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.
我有两个单选按钮,根据选择的哪个,我想将它们发送到特定的 jsp 页面。我不知道如何拉出在我的 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";
}
}
}
回答by Piyush Mattoo
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 组返回一个选中的值。