开发者

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜