从servlet Java中的请求获取未选择的单选按钮

发布于 2024-09-15 11:57:23 字数 447 浏览 2 评论 0原文

这可能看起来很奇怪,但我需要获取每个单选按钮组的未选定单选按钮的值。我已使用下面的代码来获取所有选定的按钮值,但我需要获取未选定的按钮值。

        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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很糊涂小朋友 2024-09-22 11:57:23

浏览器不会向您发送未选择的按钮。您需要做的是:

  1. 让您的代码知道所有按钮的含义
  2. 创建一个隐藏字段,其中包含所有可能值的列表。

如果您选择#2,请注意 HEBERT 先生的建议,永远不要相信用户输入。

The browser will not send you the non-selected buttons. What you'll need to do is either:

  1. Have your code know what all the buttons will be
  2. Create a hidden field with a list of all the possible values.

If you go with #2, take heed of Mr HEBERT'S suggestion to never trust user input.

舞袖。长 2024-09-22 11:57:23

您根本无法从您的请求中获取这些值。

浏览器将创建请求,并且不会发送对导航无用的信息(例如未使用的值)。

唯一的方法就是猜测这些值。

请记住,此请求可能是手工伪造的,因此永远不要相信用户输入。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文