I have a web application with a 'request' form. When a user fills out the form and submits it, if it fails validation (either front-end javascript validation or back-end
servlet validation), I'd like to keep the values they already entered so they don't have to re-type the data in. I set session attributes in my servlet to retain these values.
However, once a user successfully submits a form, if they bring up a new one, I don't want it to have the values from the last time they submitted a form - it should be a blank form, but since I'm using session attributes (session.setAttribute("foo", bar);) these values are being retained.
What is the best way to work around this?
Should I could set a field on the form to some value if validation fails, then have the servlet check that field. If it determines validation failed, I would retain the session attributes, but if not (meaning it's a new form) I would remove the session attributes? Or should I be doing something in the
jsp itself?
Or should I be going about this another way? Are session attributes the way to do it? Originally I was using request attributes, but to work around issues I was having with double submissions and with URLs showing the servlet names, I decided to go with session attributes and response.sendRedirect, rather than request attributes and requestDisplatcher.forward.
I'm guessing this must come up often and was hoping to get some suggestions on how to best deal with it. I'm very new to
java and servlets and this type of web development and would like to do this right, but I'm struggling.
Thanks for any info.