Order of request.getParameterNames()

后端 未结 5 1031
无人共我
无人共我 2021-01-04 04:36

How do I get all the parameterNames in an HTML form in the same sequence as they are in the form.

i.e if the form contains .... FirstName, LastName, MiddleName and

5条回答
  •  囚心锁ツ
    2021-01-04 04:52

    request.getParameterNames () uses HashMap internally to store the name value pairs of form fields. There is no order maintained in this. if you need this in order then , some sort of naming convention for form parameters to control the order of retrieval.

    SortedSet temp = new SortedSet();
    Enumeration enumeration = request.getParameterNames();
    while (enumeration.hasMoreElements()) 
    {
            temp.add((String)enumeration.nextElement());
    }
    

提交回复
热议问题