Redirect after POST filter ver. 1.1

This is a Java servlet filter (as per Servlet API 2.3). RedirectAfterPostFilter lets you easily implement Redirect after POST pattern in your web applications. The idea is very simple. You can map this filter to your controllers (servlets or JSP's) processing POST requests (e.g. proceeds HTML forms) and after the processing filter will redirect the original request to the url, determined by the referer header (back to the source of processed request). If this header is not available you can provide a default url for the redirection as an initial parameter for this filter.

How to use it:

a) download redirectafterpost.jar and save it in WEB-INF/lib

b) describe this filter in web.xml
 


<filter>
  <filter-name>RedirectAfterPost</filter-name>
  <filter-class>com.cj.rap.RedirectAfterPostFilter</filter-class>
</filter>

You can provide an initial parameter redirect for setting the deafault redirection. Also you may exclude some of your files from the processing. Parameter exclude contains a commas separated list of urls excluded from the processing. E.g.:
 


<filter>
  <filter-name>RedirectAfterPost</filter-name>
  <filter-class>com.cj.rap.RedirectAfterPostFilter</filter-class>
  <init-param>
    <param-name>exclude</param-name>
    <param-value>/login.jsp,/form.jsp</param-value>
  </init-param>
  <init-param>
    <param-name>redirect</param-name>
    <param-value>/main.jsp</param-value>
  </init-param>
</filter>

c) describe a mapping for this filter in web.xml
 


<filter-mapping>
  <filter-name>RedirectAfterPost</filter-name>
  <url-pattern>/servlet/MVC</url-pattern>
</filter-mapping>

now if you have some form in your JSP files like this
 


<form method="POST" action="/servlet/MVC">
...
</form>

filter lets you proceed the form (invoke /servlet/MVC) and redirect back to the original page after that.
 

    For downloading:   redirectafterpost.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: