How do I take values from a row that are in a jstl list and send them into the respective input text on the same jsp page?

Asked

Viewed 337 times

0

Good afternoon guys! I’m using "Jsp, Servlets, and jstl". I have a list where I have a link called change, when I click I get the values from that list line and send to the same jsp where there is a form with the fields to be able to make the change, so far I’m only able to make the values appear in the page url, but I can’t display them in jsp fields.

I’m sending the fields this way

<td> <a href="view/v_configura_turma.jsp?&id_turma=${listat.turma_id}&nome_turma="${listat.tur_nome}></a>  </td>   

And getting on the other jsp this way

<div>
   <input type="text" name="id_turma" id="id_turma" readonly="true" class="form-control" placeholder="Registro da turma" required="" value="${param.turma_id}"/>
</div>
</br>
<div>
    <input type= "text" name="nome_turma" id="tur_nome" class="form-control" placeholder="Nome da turma" required="" value="${param.tur_nome}" />
</div>

is and the URL that is coming on the other page

http://localhost:43183/Chamada_online/view/v_configura_turma.jsp? &id_turma=1&nome_turma=TESTE5

Thanks already!! I’m still learning how to use stackoverflow if my question is poorly formatted I will edit ready :)

1 answer

0

Good afternoon guys, I couldn’t do it directly , so I simply took the id of the selected line and made a new query in the bank where I recovered the values and insert them in the input text to make the changes.

My jsp in the list line request looks like this.

<td> <a href="./Turma_conf?funcao=recebe&id_turma=${listat.turma_id}/></td>

My Serrvlet looks like this ,it takes a parameter where the function to be executed is chosen.

String funcao = request.getParameter("funcao");

Run the function receives where it sends to the DAO method where the id search is done and receives the id values as a return to Servlet and in the sequence sent to jsp by filling in the fields.

The way my Birch looked below.

if(funcao.equals("recebe")){            
                    int turma_id = Integer.parseInt( request.getParameter("id_turma"));                                                                         
                    tb = tur.turma_busca_pk(turma_id);
                    request.setAttribute("turma", tb);                                           
                    RequestDispatcher rd = request.getRequestDispatcher("configura_turma.jsp");
                    rd.forward(request, response);

My DAO method follows below if it helps more people search by id. it receives the id and query the database receiving 8 return parameters.

public TurmmaBean turma_busca_pk (int id_turma){
    TurmmaBean turma = new TurmmaBean();
    String sql  ="select * from turma where tur_turma_id ="+id_turma;
    try {
    ps = con.prepareStatement(sql); 
    rs = ps.executeQuery(sql);
   if (rs.next()){

            turma.setTurma_id(rs.getInt("tur_turma_id"));
            turma.setTur_nome(rs.getString("tur_nome"));
            turma.setTur_diciplina(rs.getString("tur_diciplina"));
            turma.setTur_ini_dia( new java.sql.Date (rs.getDate("tur_inicio").getTime()));
            turma.setTur_fim_dia(new java.sql.Date(rs.getDate("tur_fim").getTime()));
            turma.setTur_hora_inicio(rs.getTime("tur_hora_inicio"));
            turma.setTur_hora_fim(rs.getTime("tur_hora_fim"));
            turma.setTur_dia_semana(rs.getString("tur_dia_semana"));

   }
           rs.close();
           ps.close();
      } catch (Exception e) {
          throw new RuntimeException("Erro 1_D   " + e);
      }

return turma;
}

From now on thank you guys!!!! : ) Happy Holidays to the end of 2018.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.