从servlet Java中的请求获取未选择的单选按钮
这可能看起来很奇怪,但我需要获取每个单选按钮组的未选定单选按钮的值。我已使用下面的代码来获取所有选定的按钮值,但我需要获取未选定的按钮值。
ArrayList <String> userSelection = new ArrayList <String>();
Enumeration names = request.getParameterNames();
String selection = "";
while ( names.hasMoreElements() )
{
name = (String) names.nextElement();
userSelection.add(request.getParameter( selection ));
}
It may seem strange, but I need to get values of non-selected radio buttons for each radio button's group. I have used the code below to get all the selected buttons values, but I need to get the unselected ones.
ArrayList <String> userSelection = new ArrayList <String>();
Enumeration names = request.getParameterNames();
String selection = "";
while ( names.hasMoreElements() )
{
name = (String) names.nextElement();
userSelection.add(request.getParameter( selection ));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器不会向您发送未选择的按钮。您需要做的是:
如果您选择#2,请注意 HEBERT 先生的建议,永远不要相信用户输入。
The browser will not send you the non-selected buttons. What you'll need to do is either:
If you go with #2, take heed of Mr HEBERT'S suggestion to never trust user input.
您根本无法从您的请求中获取这些值。
浏览器将创建请求,并且不会发送对导航无用的信息(例如未使用的值)。
唯一的方法就是猜测这些值。
请记住,此请求可能是手工伪造的,因此永远不要相信用户输入。
You simply can't get those values form your request.
It's the browser which will create the request and it doesn't send informations that appears useless for the navigation (such as unused values).
The only way to do that would be to guess the values.
Remember this request could be forged by hand so, never trust user input.