-1
Hello. I’m developing a system where the user clicks on an edit button and then opens the editing page with the attributes of the already filled object in the text boxes.
In my Servlet, I am 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 it’s not showing the ID on JSP. Could someone help me?
Haha sorry, the truth is that this up there is not working, IE, the id does not appear in JSP
– Adão Lima