I have a payment form. When user submit the form the payment process runs successfully, but clicking the back button brings user to same form. I want to expire the form after successful submission, to prevent user from multiple payment (in case user goes back and submit form). Following Prevent user from going back tutorial, I added the filter but it's not working for me. What am I doing wrong? Here is what I added for filtering.
<filter>
<filter-name>paymentFilter</filter-name>
<filter-class>path to PaymentFilter class</filter-class>
</filter>
<filter-mapping>
<filter-name>paymentFilter</filter-name>
<url-pattern>/order/*/payment</url-pattern>
</filter-mapping>
and my filter class is
public class PaymentFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
httpServletResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0.
httpServletResponse.setDateHeader("Expires", 0); // Proxies.
System.out.println("In filter");
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
I have added a System.out.println("In filter")
but I can't see its output ("In filter") on console after running the page.
When I use the URL pattern as /*
the System.out
prints on console,
<url-pattern>/*</url-pattern> (it works as expected)
but when I change the URL pattern to /order/*/payment
(* is order id what changes for each order). then System.out
does not print anything on console.
<url-pattern>/order/*/payment</url-pattern> (it doesn't work)
I am using spring mvc, apache, tomcat7.0
What gave me the solution to my problem is that i "can not" user regular expression in my url-patter for filter mapping. * can only be use as suffix or prefix.