1. Home
  2. Knowledge Base
  3. On premise
  4. Application Server
  5. How to solve trailing slash (/) in Tomcat 7+

How to solve trailing slash (/) in Tomcat 7+

Tomcat is not adding trailing slash (/) to web app’s context (example: APPLICATION.COM/TEST/)

When you have Tomcat 7.0.67 or higher, you need to add the following attribute to your context.xml

<Context mapperContextRootRedirectEnabled=”true”>…</Context>

As per the 7.0.67:
Move the functionality that provides redirects for context roots and directories where a trailing / is added from the Mapper to the DefaultServlet. This enables such requests to be processed by any configured Valves and Filters before the redirect is made. This behaviour is configurable via the mapperContextRootRedirectEnabled and mapperDirectoryRedirectEnabled attributes of the Context which may be used to restore the previous behaviour.


And in the Tomcat context documentation:
mapperContextRootRedirectEnabled: If enabled, requests for a web application context root will be redirected (adding a trailing slash) if necessary by the Mapper rather than the default Servlet. This is more efficient but has the side effect of confirming that the context path exists. If not specified, the default value of false is used.

Was this article helpful?

Related Articles