In my application I have many different JSP forms with multiple stages, that is after each stage the request is send to the Servlet and processed to generate the next form.
The problem is that I need to keep the state of these forms (like in JSF where it is done automatically), so that the user won’t have to eneter all the data each time he gets to the error page or navigates back to reenter something he wants to change.
What is the best approach:
1) Store all data in the session, and remove it once the user submitted the final stage of the form.
2) Store it all in the request scope, and read/write each time the user navigates to the different page. However, this does not seem logical since if I save stage 1 and need its data in stage 4, I have to read/write it 3 times instead of just 1 time when using the session scope, and each time the amount of data to be read/written increases.
Both are doable, it depends on your use-case.
If you need a calculation after each step and need to send data to the server anyways, session is better.
If client is Javascript heavy, you can collect all data and only send it after the final step. This would work only if the steps do not depend on data entered.
If you go for the session approach, be careful to make it work when the user opens your app in multiple tabs. This could be done by detecting the session attribute already in the session, or naming the attribute in a way that does not cause conflict.