禁用 cookie 时,C:url 不附加 jsessionid

发布于 2024-10-12 01:42:25 字数 233 浏览 1 评论 0原文

我尝试过:

<c:url value="/web/pclub/userprofile" var="test">
    <c:param name="userid" value="${user.id}"/>
</c:url>
${test}

但是当我检查禁用 cookie 的页面时,不会附加 jsessionid。 有谁知道为什么会发生这种情况?

I tried:

<c:url value="/web/pclub/userprofile" var="test">
    <c:param name="userid" value="${user.id}"/>
</c:url>
${test}

But when I check the page with cookies disabled then the jsessionid is not appended.
Does anyone know why this happens?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宫墨修音 2024-10-19 01:42:25

jsessionid仅在cookie被禁用时在服务器端创建会话时附加(因此服务器端需要以某种方式通知客户端, cookie 是默认方法)。如果尚未创建会话,则没有必要附加 jsessionid

尝试将以下行添加到 JSP 顶部,至少在调用 行之前。它不仅为您打印/调试会话 ID,而且还会隐式创建会话(如果尚未完成)。

${pageContext.session.id}

执行此操作仅用于测试目的。如果它有效,那么问题的原因是没有会话的方法。保持原样即可。无需创建不必要的会话。对于存在会话并且浏览器不支持 cookie 的情况,c:url 就可以正常工作。


顺便说一句,要验证 cookie 是否确实被禁用,请通过 Firebug 跟踪请求标头。如果服务器在响应中设置了 Set-Cookie 标头,但请求中没有 Cookie 标头,则意味着 Cookie 确实在客户端被禁用。

The jsessionid is only appended when the cookies are disabled and when a session has been created on the server side (and thus the server side needs to notify the client about this somehow, for which a cookie would is the default approach). If no session has been created, then there's no point of appending the jsessionid.

Try adding the following line to top of your JSP, at least before the <c:url> line is called. It not only prints/debugs the session ID for you, but it also implicitly creates the session if not done yet.

${pageContext.session.id}

Do this for testing purposes only. If it works, then the cause of your problem is that there was just no means of a session. Just keep it as is. There's no need to unnecessarily create the session. For the case whenever there's as session and the browser doesn't support cookies, the c:url will work fine.


By the way, to verify if the cookies are indeed disabled, track the request headers by Firebug. If there's no Cookie header in the request even though the server has set a Set-Cookie header in the response, then it means that the cookies are indeed disabled in the client side.

偏闹i 2024-10-19 01:42:25

我认为 BalusC 是正确的,但是要强制在服务器上创建会话,您可以在 JSP 顶部添加一个指令页面,如下所示:

<%@ page session="true" %> 

I think BalusC is right, however to force creating a session on the server, you can add a directive page on the top of your JSP, like this:

<%@ page session="true" %> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文