I need to show the result of a sum in a redirected page, I tried a "setAttribute" after the "Redirect" but it does not work. The sum value would have to go to an "input" on the next page, or a simple " <h1>
". The part of the "request", where the summation begins, is all ok.
I have the following method:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try (PrintWriter out = response.getWriter()) {
int soma = Integer.parseInt(request.getParameter("a")) + Integer.parseInt(request.getParameter("b"));
response.sendRedirect("resultado.jsp");
response.getContentType();
request.setAttribute("result", soma);
}
}
And the following code on the .jsp page:
<h1> Resultado da soma: <input type="number" name="result"> </h1>