Update data from an HTML page with JSP

Asked

Viewed 103 times

1

I’m making a simple JSP system, where the program should simply fetch a float in a database and then add it to a variable. Everything is working, but I can’t make this information be shown by HTML, follow my code:

<form name="orc" method="post" action="#">
    <select name="tratamentos">
            <%float preco = 0;
            Integer x = 0;
            DAOTratamento dao = new DAOTratamento();
            ArrayList<Tratamento> listaTratamento = new ArrayList<Tratamento>();
            listaTratamento = dao.searchAll();
            for(Tratamento t : listaTratamento){%>
            <option value=<%out.println("tratamento"+x); x++%> ><%out.println(t.getNome());%></option>
            <% } %>
            <input type="submit" name="submit" value="Adicionar"/>
            </form>
             <% 
                       String s = request.getParameter("tratamentos");
                       if (s !=null)
                       {
                           Tratamento tratamento = new Tratamento();
                           tratamento = dao.searchByName(s);
                           preco+= tratamento.getPreco();
                       }
              %>
              <h1>Preço: R$<%out.println(preco);%></h1>
  • What’s going on? What should happen?

  • Nothing is happening and should update the value shown in <H1>Price: R$<%out.println(price);%></H1>

No answers

Browser other questions tagged

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