URL Rewrite for Java Applications
Here are the steps for implementing URL Rewrite in your Java based Web Applications.
1. Download URL Rewrite Library
2. In your web.xml insert the following lines:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. Copy urlrewrite.xml inside WEB-INF
4. Configure urlrewrite.xml by adding your “rules”
e.g.
<rule>
<note>User Login</note>
<from>/user/login</from>
<to type=”redirect”>%{context-path}/manageLogin.do?action=showLoginPage</to>
</rule>
Explanation: Whenever the user goes to a page in your application who’s URL ends with “/user/login”(mentioned in the “from” element), he will be redirected to “/manageLogin.do?action=showLoginPage” of your application(mentioned in the “to” element).
5. Restart your server