0

I have two forms, a.jsp & b.jsp.

When the first form is submitted, a Java servlet (ex. a_servlet.java) will be called which generates a requestID and redirects to b.jsp.

I need to pass the requestID generated from a_servlet to b_servlet.

I currently use the code below, but I have a feeling it is not thread safe, by that I mean, if a 2nd user fills a.jsp form before the 1st user finishes filling b.jsp form, there will be a requestID mix-up.

In a_servlet.java:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//....
request.getSession().setAttribute("reqid", reqid);
//.... }

In b_servlet.java:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//....
String reqid = (String) request.getSession().getAttribute("reqid");
//.... }

Is there some solidation I need to do to make passing data between servlets thread-safe ?

Is there a better way? Maybe storing the requestID on the user side in a hidden HTML attribute in b.jsp comes to mind, but it doesn't feel right.

Maroun
  • 87,488
  • 26
  • 172
  • 226

0 Answers0