Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How (in ServletFilter) redirect someone to saved POST request?  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If someone POSTed information from a form but we're authorized to, and it redirected them to a login page (and the filter saved the data from that posted request in the session or somewhere else) and they then login, how can I redirect them back to that form's action?

Is the only way to fully implement my own HttpServletRequest that copies most of the info from the current request but changes/replaces all the saved data, and then passes this on down the filter chain: filterChain.doFilter( newRequest, response )? Is that even possible? is there a better way?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you've got the action, the method (get or post) and the map of request parameters, you're in a position to recreate the interrupted request.

One path of least resistance might be to forward to a JSP that dynamically constructs a form from that info with the appropriate action and method filled in, and a bunch of hidden parameters for each of the request params. A JavaScript function registered as the onload hander can cause the form to be immediately submitted thus recreating your interrupted request.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
If you've got the action, the method (get or post) and the map of request parameters, you're in a position to recreate the interrupted request.

One path of least resistance might be to forward to a JSP that dynamically constructs a form from that info with the appropriate action and method filled in, and a bunch of hidden parameters for each of the request params. A JavaScript function registered as the onload hander can cause the form to be immediately submitted thus recreating your interrupted request.



First off, thanks for the response!

The reason I think my idea might work better is that forwarding to a form that then gets submitted requires more back-forth trips, more processing, time, load, etc. It'd almost be like every user that does that is equivalent to 3 users. If my idea is feasible (and unless someone suggests something better I'm going to try it) I think it's the quickest way to get them back to the original state/request. What do you think?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I said "path of least resistance" not "most architecturally elegant".

Sure, if you can figure out where to forward to based upon the stored action value, you can implement a request wrapper that contains the saved parameters. The forwarded resource will be fooled into thinking that they're the real params and happily process along.

Look up "request wrapper" in this forum (or google) for more details.
[ August 10, 2006: Message edited by: Bear Bibeault ]
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
I said "path of least resistance" not "most architecturally elegant".

Sure, if you can figure out where to forward to based upon the stored action value, you can implement a request wrapper that contains the saved parameters. The forwarded resource will be fooled into thinking that they're the real params and happily process along.

Look up "request wrapper" in this forum (or google) for more details.

[ August 10, 2006: Message edited by: Bear Bibeault ]


Thanks! I'll check that out.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our requests all come through one servlet, then to some ActionClass-like things (home-made, not Struts). We made it save the action class name and form data to the session, redirect to the login page, post to a special action class that gets that stuff back off the session and calls the originally requested action class. Whew. It ain't pretty, but might work if your structure supports it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!