简体   繁体   English

如何从JSP中的URL中检索jsessionid?

[英]How do I retrieve the jsessionid from URL in JSP?

I know how to pass the jsessionid to the URL. 我知道如何将jsessionid传递给URL。 I encode the url, which will look like this: 我编码url,它看起来像这样:

mysite.com;jsessionid=0123456789ABCDEF (http) mysite.com; jsessionid = 0123456789ABCDEF(http)

Does there exist a built-in method to retrieve the jsessionid from the URL, using Java? 是否存在使用Java从URL检索jsessionid的内置方法? I found this method in the javadocs , isRequestedSessionIdFromURL, but it doesn't help me actually retrieve the value. 我在javadocs中找到了这个方法,isRequestedSessionIdFromURL,但它并没有帮我实际检索该值。 Do I have to build my own retrieval method? 我是否必须构建自己的检索方法?

Thank you. 谢谢。

JSP has an implicit session object, similar the request object. JSP有一个隐含的session对象,类似于request对象。 It is an instance of java.servlet.http.HttpSession , which has the method getId() . 它是java.servlet.http.HttpSession一个实例,它有getId()方法。

So, you should be able to just do session.getId() in your JSP page. 因此,您应该能够在JSP页面中执行session.getId()

Cookieless sessions are achieved in Java by appending a string of the format ;jsessionid=SESSION_IDENTIFIER to the end of a URL. 无Java会话通过在Java中附加格式的字符串来实现;jsessionid=SESSION_IDENTIFIER到URL的末尾。 To do this, all links emitted by your website need to be passed through either HttpServletRequest.encodeURL(), either directly or through mechanisms such as the JSTL tag. 为此,您的网站发出的所有链接都需要通过HttpServletRequest.encodeURL()直接或通过JSTL标记等机制传递。 Failure to do this for even a single link can result in your users losing their session forever. 即使单个链接无法执行此操作也可能导致您的用户永远丢失其会话。

session.getId() should be able to get you the session id. session.getId()应该能够获得会话ID。 WLS would be doing the actual parsing of the URl to retrieve the session id once it identifies that the session id is not stored in the cookie or in hidden form fields. 一旦确定会话ID未存储在cookie或隐藏表单字段中,WLS将对URl进行实际解析以检索会话ID。 The sequence usually is Cookie - URL - Hidden Form Fields. 序列通常是Cookie - URL - 隐藏表单字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM