getParameter returning the same value

0

I have a table where you have the column

ID - NAME - ACTION
1 - USU1 - SEE
2 - USU2 - SEE
3 - USU3 - SEE

In the JSP I am saving the id inside an input hidden.

<input type="hidden" value="${operador.id }" name="idOperador"/>

In Java I call this value through

int id = Integer.parseInt(request.getParameter("idOperador"));

However, regardless of the item I click on "SEE", it is taking the value of the first row of the table . In this case the id "1" or the first of the next pages.

Any guidance?

Part of the code: This is inside a table, where one of the columns (actions) consists of the action buttons (view, change, and delete). When you select the change option, it is taking the id of the first row of the table.

Note: this is inside a foreach (JSTL)

<td class="actions">
   <input type="hidden" value="${operador.id }" name="idOperador"/>
   <div align="center">
      <div class="btn-group" role="group">
      <button type="button" class="btn bg-cyan waves-
      effect">Visualizar</button>
      <button type="submit" name="command" value="DadosAlterarOperador" 
      class="btn bg-cyan waves-effect">Alterar</button>
      <button type="button" class="btn btn-danger waves-
      effect">Excluir</button>
   </div>
 </div>
</td>
    
asked by anonymous 25.07.2017 / 04:33

2 answers

0

The getParameter () return only the first element found. In your case as it is a list of elements it is ideal to use the getParameterValues ()

//o metodo retorna um array de Strings
String[] ids = request.getParameterValues("idOperador");

for(int i = 0;i < ids.length; i++)
{
   //pega o id desejado da lista
   int id = Integer.parseInt(ids[i]);
}
    
26.07.2017 / 17:55
0

InyourexampleIdonotgetseveral"ids" but the one I click on the button.

Its ID gets written to the foreach of the JSP and then I get 1 unique ID with getParameter in Java.

    
29.07.2017 / 04:38