且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

URL中出现JSESSIONID后,我的Web应用程序停止工作

更新时间:2022-11-08 15:34:41

这显然是由Cookie路径不匹配引起的.

This is apparently caused by cookie path mismatch.

仅当请求URL路径与Cookie路径匹配时,浏览器才会发回Cookie.

Browser will only send back the cookie if the request URL path matches the cookie path, e.g.

 cookie path :  /abc
request path:   /abc/xyz   // match
request path:   /xyz       // no match

默认情况下,Tomcat将会话cookie路径设置为Web应用程序路径,这样就不会将cookie发送到其他Web应用程序.但是,在您的情况下,中间件会更改请求URL路径,因此浏览器会观察到其他路径,从而导致Cookie路径不匹配.

By default, Tomcat set the session cookie path as the web app path, so that the cookie will not be sent to other web apps. However, in your case, the middleware changes the request URL path, therefore the browser observes a different path, causing cookie path mismatch.

在大多数情况下,我建议将cookie路径设置为"/",以使其与对服务器的所有请求相匹配(假设Tomcat上只有一个应用程序)

In most cases, I'd recommend to set cookie path to "/", so that it matches all requests to the server (assuming there's only one app on Tomcat)

// context.xml
<Context sessionCookiePath="/">