• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem with validation  RSS feed

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three ways to go on this:

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.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!