开发者

Getting a non-selected radio buttons from request in servlet Java

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开发者_如何学JAVA 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 ));
        } 


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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜