0

I have a form where the input's name are :

<form>
<div class="form-group" >
    <div class="col-md-1">                                      
        <input type="text"  class="form-control"  name="product[]"/>        
    </div>

    <div class="col-md-4">
        <input type="text" class="form-control" name="description[]"/>
    </div>
</div>

<div class="form-group" >
    <div class="col-md-1">                                      
        <input type="text"  class="form-control"  name="product[]"/>        
    </div>

    <div class="col-md-4">
        <input type="text" class="form-control" name="description[]"/>
    </div>
</div>

<div class="form-group" >
    <div class="col-md-1">                                      
        <input type="text"  class="form-control"  name="product[]"/>        
    </div>

    <div class="col-md-4">
        <input type="text" class="form-control" name="description[]"/>
    </div>
</div>
</form>

I am wondering if I can read these values from my servlet.. Is there a way to iterate through all the inputs product[] and description[]?

I tried String[] description = request.getParameterValues("description[]"); and

while(!StringUtils.isBlank(request.getParameter("description[]"))){
   String description = request.getParameter("description[]");
   System.out.println("desct = " + description);
}

but it didn't read the values..

yaylitzis
  • 5,354
  • 17
  • 62
  • 107

3 Answers3

0

Java Servlet - get parameters with same name

So String[] description = request.getParameterValues("description"); might work!? Without the [] in the name.

Community
  • 1
  • 1
Jack Flamp
  • 1,223
  • 1
  • 16
  • 32
0

After @JozefChocholacek comment I found where the problem was. There was the attribute disabled in the input form. I deleted and then the

while(!StringUtils.isBlank(request.getParameter("description[]"))){
   String description = request.getParameter("description[]");
   System.out.println("desct = " + description);
}

worked just fine.

yaylitzis
  • 5,354
  • 17
  • 62
  • 107
-1

As you have written name="description [ ]" so you should get the value/values by this name only.

So your statement should be:

String[] description = request.getParameterValues("description[ ]");
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34