0

Hy, I have a code who intercept all request(GET & POST), and eventually redirect to another page, with a form. I want that when the user post the form, the initial intercepted request is executed

My actual code:

public void doFilter(ServletRequest originalRequest, ServletResponse res, FilterChain chain){
  originalRequest.getRequestDispatcher("/message").forward(request, res);
}

...

@RequestMapping("/message", method=GET)
public void showMessageForm(...){
...
}
@RequestMapping("/message", method=POST)
public void messageOk(ServletResponse res, ModelAndView mav){
//redirect to the originalRequest.
  ????
}

The originalRequest can be both GET or POST. If it's a post, I want the content of the form to be transmit too.

Thank you !

sab
  • 4,352
  • 7
  • 36
  • 60
  • What is messageOk going to do? Do you want it to send them back to the original URL that was requested? – Dave Feb 11 '16 at 17:52
  • Yes. As a post if the original request was a POST. – sab Feb 11 '16 at 21:09
  • You can't use an HTTP redirect to a POST. But I'm not sure that is what you want to do. Need a little more information. What is the purpose of your messageOk handler? – Dave Feb 12 '16 at 14:59
  • Just show a page one time, after some action of the user . sometimes the user do a post, sometimes a get, and the interceptor catch the request before the endpoint to show this messagePage. After the user have fill the form on the page(send by POST), the interrupted request have to run. – sab Feb 12 '16 at 15:29
  • Will the page that is displayed have some sort of "OK" or "Continue" link or button the user will interact with? – Dave Feb 12 '16 at 16:40
  • Yes, it's how it work, why? – sab Feb 15 '16 at 09:13

1 Answers1

1

Your messageOk method will need to return a page with a form that has hidden fields for each field they passed + an Ok button. So something like:

<form method="POST or GET" action="origin url">
  <input type="hidden" name="param1" value="value for param1"/>
  ... for each input ...
  <input type="hidden" name="paramN" value="value for paramN"/>
  <input type=submit" value="Continue"/>
</form>

This should work as long as you don't have a POST that is uploading a file. You might want to consider a simpler flow in your application, like forcing this page only when somebody logs in.

Dave
  • 13,518
  • 7
  • 42
  • 51