I am currently writing the section of a program where the results are shown on page (taken from a form) and the user is able to double check them before clicking a button and sending the data off to be processed. The only problem is I am having trouble sending the data between the ResultsServlet and the ResultsProcessorServlet. I'll put some code to try and explain:
public class ResultServlet extends HttpServlet {
// User inputted data which has been taken from the form over POST
String jobNumber;
String projects;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
... //Some initial processing of form data.
resp.setContentType("text/html");
resp.setStatus(HttpServletResponse.SC_OK);
PrintWriter out = resp.getWriter();
//Display the data on screen with some html and a button to confirm
out.println(...);
}
}
Once the user is happy with the data, the idea would be that they can press a button which will send the data to the next servlet below:
public class ProcessorServlet extends HttpServlet {
String jobNumber;
List<String> projects;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//Do stuff with the data
...
}
}
In a standard case, I realise I could just use req.setAttribute() and req.getAttribute() to redirect the data across the servlets. The only issue with this is that I only want to do that once the user has pressed the 'Confirm' button. I'm just having trouble linking everything together so any help would be nice. It's also probably worth noting that I am generating the html using the j2html package.
Cheers.