Class HideJspExtensionFilter

java.lang.Object
com.aoapps.servlet.filter.HideJspExtensionFilter
All Implemented Interfaces:
Filter

public class HideJspExtensionFilter extends Object implements Filter
A servlet filter that hides the .jspx or .jsp extension from JSP-based sites. It accomplishes this with the following steps:
  1. Rewrite any URLs ending in "/path/index.jsp(x)" to "/path/", maintaining any query string
  2. Rewrite any URLs ending in "/path/file.jsp(x)" to "/path/file", maintaining any query string
  3. 301 redirect any incoming GET request ending in "/path/index.jsp(x)" to "/path/" (to not lose traffic after enabling the filter)
  4. 301 redirect any incoming GET request ending in "/path/file.jsp(x)" to "/path/file" (to not lose traffic after enabling the filter)
  5. Forward incoming request of "/path/" to "/path/index.jsp(x)", if the resource exists. This is done by container with a welcome file list of index.jsp(x) in web.xml.
  6. Forward incoming request of "/path/file" to "/path/file.jsp(x)", if the resource exists
  7. Send any other request down the filter chain

When both *.jspx and *.jsp resources exist, the *.jspx is used.

This should be used for the DispatcherType.REQUEST and DispatcherType.ERROR dispatchers.

In the filter chain, it is important to consider the forwarding performed by this filter. Subsequent filters may need DispatcherType.FORWARD dispatcher in addition to DispatcherType.REQUEST to see the forwarded requests.

Note: When testing in Tomcat 7, /WEB-INF/ protection was not compromised by the forwarding. Requests to /WEB-INF/ never even hit the filter.

See Also: