在 Tomcat 中支持没有 Cookie 的会话 [英] Supporting Sessions Without Cookies in Tomcat
问题描述
我目前正在运行具有以下属性的应用程序:
I am currently running an application with the following properties:
- 基于 Java 的 Spring 和 Acegi
- 在 Tomcat 5 上运行
我需要能够支持没有 cookie 的用户会话.有人可以指出我正确的方向.
I need the ability to support user sessions without cookies. Could someone please point me in the right direction.
谢谢.
推荐答案
这个问题的完整答案是你所有回答的组合,所以我要总结一下:
The complete answer to this question is a combination of all your responses, so I'm going to summarize:
无需在 context.xml 文件中设置 cookies="false".理想的功能是让 tomcat 使用它的基于 url 的会话标识,如果用户不支持 cookie,它将默认使用.
There is no need to set cookies="false" in the context.xml file. The ideal functionality is for tomcat to use it's url-based session identification, which will be used by default if cookies are not supported by the user.
当用户没有启用 cookie 时,tomcat 将通过来自请求 url 的JSESSIONID"参数识别会话.几个示例网址如下http://www.myurl.com;jsessionid=123456AFGT3
http://www.myurl.com;jsessionid=123456AFGT3?param1=value¶m2=value2
注意会话 id 不是 url 查询字符串的一部分(这是 j2ee 标准)
When a user doesn't have cookies enabled, tomcat will identify the session by the "JSESSIONID" parameter from the url of the request. A couple sample urls are as follows
http://www.myurl.com;jsessionid=123456AFGT3
http://www.myurl.com;jsessionid=123456AFGT3?param1=value¶m2=value2
Notice how the session id is not part of the url query string (this is a j2ee standard)
为了确保将 jsessionid 参数附加到您的所有请求 URL,您不能有简单的 url 引用.例如,在 JSTL 中,您必须使用 <网址:网址>.如果需要,servlet 引擎会自动将 jsessionid 附加到 url 中.举个例子:
In order to ensure the jsessionid parameter gets appended to all your request URLs, you can't have plain url references. For example, in JSTL, you have to use < c:url>. The servlet engine will then automatically append the jsessionid to the url if it is necessary. Here's an example:
<%--这很糟糕:--%><a href="page.html">链接
<%--这很好:--%><a href="< c:url value='page.html'/>">链接
这篇关于在 Tomcat 中支持没有 Cookie 的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!