Tomcat is not adding trailing slash to web app's context

后端 未结 5 1469
自闭症患者
自闭症患者 2020-12-09 10:10

I\'d like to have Tomcat automatically add a trailing slash to my app\'s context if the url is entered without it.

When I test with Jetty, it automatically adds the

5条回答
  •  感动是毒
    2020-12-09 10:37

    Pat's excellent answer helped me dig up a few more details on this. It seems this is related to some quirks in some versions of Tomcat (Tomcat 7 at 7.0.67+, and Tomcat 8 between 8.29 and 8.37) having to do with session cookies and URL redirection.

    The bottom line seems to be that if the java server creates path-specific session cookies with a slash at the end (like "/app_name/"), then the server must also do an automatic initial redirect (/app_name --> /app_name/) ... otherwise, the session cookie will not get sent with the request, and it will never look to the server like you have a valid session. The may cause a redirect loop from the app to the authentication.

    There are configurations in Tomcat that control both behaviors, but as far as I can tell, they were essentially out-of-sync in these versions, such that one might get the cookie with the trailing slash, without getting the redirect. There are several related issues/changes in the Tomcat changelog: https://tomcat.apache.org/tomcat-8.0-doc/changelog.html

    As Pat has already noted, this is resolved by adding this attribute to your app's Context element:

    
    

提交回复
热议问题