Hello. I'm developing a system where the user clicks an edit button and then opens the edit page with the attributes of the object already filled in the text boxes.
In my servlet, I'm using the following logic:
Moto escolhida = new Moto();
try {
MotoDao dao = new MotoDao();
List<Moto> motos = dao.consulta();
//monta o objeto moto a partir do id_moto
for (Moto m : motos) {
if (id_moto == m.getId()) {
escolhida = m;
}
}
System.out.println("dados da moto: "+ escolhida.getId()+" / "+escolhida.getModelo() );
//passa os atributos da moto escolhida para a jsp
request.setAttribute("id_moto", escolhida.getId());
request.setAttribute("marca", escolhida.getMarca());
request.setAttribute("modelo", escolhida.getModelo());
request.setAttribute("potencia", escolhida.getPotencia());
request.setAttribute("ano", escolhida.getAno());
request.setAttribute("valor", escolhida.getValor());
request.getRequestDispatcher("editar.jsp").forward(request, response);
In my JSP:
<td> ID:</td> <td> <input type="text" name="id_moto" value="<%request.getAttribute("id_moto"); %>" required /></td>
In theory, this would work, but the ID in the JSP is not appearing. Could someone help me?