Olá estou tentando fazer um exercício básico de jsp e servlet. é uma calculadora simples que envia os dados para o servlet e retorna o resulta para a própria pagia no jsp…
Alguem pode me ajudar…
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style>
.cor{
color: blue
}
</style>
</head>
<body>
<form action="Calcular" method="post">
<table>
<tr>
<td style="color: blue">Entre com valor: </td>
<td><input name="campo1" type="text"/></td>
</tr>
<tr>
<td class="cor">Entre com valor: </td>
<td colspan="2"><input name="campo2" type="text"/></td>
</tr>
<tr>
<td class="cor">Limpar Campo: </td>
<td colspan="2"><input name="campo3" type="text" value="<%=campo3%>"/></td>
</tr>
<tr>
<td><input name="btSomar" type="submit" value="Somar"/></td>
<td><input name="btLimpar" type="reset" value="Limpar"/></td>
</tr>
</table>
</form>
</body>
</html>
servlet
protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String camp1 = request.getParameter("campo1");
String camp2 = request.getParameter("campo2");
double a = Double.parseDouble(camp1);
double b = Double.parseDouble(camp2);
String s = new String();
s = String.valueOf(a + b);
request.setAttribute("campo3", s);
response.sendRedirect("index.jsp");
}
so não consigo passar o valor para o 3 campo…