0
I need to show the result of a sum on a redirected page, I tried a "setAttribute" after "Redirect" but it doesn’t work. The sum value would have to go to an "input" on the next page, or on an "<h1>
" simple. The "request" part where the sum starts 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>
I think it is enough just to receive on the page the attribute "result", <input type="number" name="result" value="{$result}">
– sant0will