I'm doing a simple system in JSP, where the program should simply fetch a float from a database and then add it to a variable. Everything is working, but I can not get this information to be displayed 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>