suppose I have Action A that does request.setAttribute(..) before forward the view to a.jsp. in a.jsp there's a button that calls Action B, if B encounters and an error naturally the view gets set to a.jsp. Now there's a problem because a.jsp no longer has access to the attribute that was stored in the original request because it's a new request(?) I have to redo Action A's logic such as request.setAttribute(..) in action B in case there's an error.. Is there a better way? thanks
A. Store the object in session scope, rather than the request. This is easy to implement, but can cause performance problems in the long run if the object contains a lot of data and you are expecting a lot of concurrent users. If the object is small, though, this is really the best way to go.
B. Use Hidden fields to store the information. That way, it will get passed on with each form submission. Beware, though, of the possiblity of "spoofing" when using this technique. This means, the user could alter the information in the hidden fields and re-submit the form.
C. Just bite the bullet and get the information from the database again. Most RDBs use caching anyway, so this may not be as expensive as you might think. If speed is really critical, consider implementing your own caching mechanism.