I've gone through similar questions on this site and still in doubt with it.
I have a basic calculation on one servlet call add servlet
and want to get user input to show the total on the same JSP page via another servlet called view total servlet
(a table view).
E.g. addServlet
on doGet
int i = Integer.parseInt(request.getParameter("add"));
int subTotal = 10 + i;
System.out.println("subtotal is (servlet) = " + subTotal);
// session mgmt to share data
request.setAttribute("subTotal", subTotal);
RequestDispatcher rd = request.getRequestDispatcher("view_total");
rd.forward(request, response);
The `view total servlet` on doGet
// get input from add servlet
int subTotal = (int) request.getAttribute("subTotal");
subTotal = 0 * subTotal;
String viewTotal = "frontend/view_total.jsp";
RequestDispatcher rd = request.getRequestDispatcher(viewTotal);
rd.forward(request, response);
The JSP
<tr>
<td>1</td>
<td>$10</td>
<td><input type="text" name="add" /></td> `// get user input`
<td> ${ subTotal } /td> `// how to show total value here`
</tr>