HttpServletRequest getParameter of Radio Buttons
I want to have the parameter value of radio button.
<input type="radio" name="lang" value="Official"/>Official 开发者_StackOverflowOnly
<br/>
<input type="radio" name="lang" value="all"/>All
How do I check in java to see which one is selected?
Use HttpServletRequest#getParameter()
with the name of the input field as parameter name.
String lang = request.getParameter("lang"); // Can be null, "Official" or "all"
The value of the input field will become the parameter value.
if ("Official".equals(lang)) {
// Official selected
} else if ("all".equals(lang)) {
// all selected
}
精彩评论