我如何在Java中获取会话ID [英] How can i get session id in java
本文介绍了我如何在Java中获取会话ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Java中构建一个api,以解决在任何网站中将一页移动到另一页时发生的安全图像问题.如何获取会话ID和Cookie,以便可以将其与安全图像字符串一起发布.
I want to build an api in java to solve the security image problem occurred while moving one page to another page in any website. How can i get the session id and cookies so that i can post it with the security image string.
谢谢
推荐答案
以下应在jsp中提供会话ID
Following should give session id in jsp
如果您在容器中启用了EL,则可以在不使用JSTL标签的情况下进行操作-即
If you have EL enabled in your container, you can do it without the JSTL tag - ie just
<c:out value="${pageContext.session.id}"/>
或没有EL的容器的替代方案:
or An alternative for containers without EL:
<%= session.getId() %>
获取Cookie的示例如下:
Example to get Cookies is as :
<%
String cookieName = "username";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
if (cookies != null){
for (int i = 0; i < cookies.length; i++) {
if (cookies [i].getName().equals (cookieName)){
myCookie = cookies[i];
break;
}
}
}
%>
引用自: http://www.roseindia.net/jsp/jspcookies.shtml
这篇关于我如何在Java中获取会话ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文