Manage Session when broswer has disable cookies

柔情痞子 提交于 2020-01-12 03:42:09

问题


I wants to know that How can i Manage Session if the client browser has disabled cookie feature..

If I wants to implement it in simple JSP - Servlet, then how can I do that ?

Thanks in advance...


回答1:


In the JSP side, you can use JSTL's <c:url> for this.

<a href="<c:url value="page.jsp" />">link</a>

Easy as that. It will automagically append the jsessionid when cookies are disabled.

In the Servlet side you need HttpServletResponse#encodeURL() or -usually the preferred one inside Servlets- HttpServletResponse#encodeRedirectURL() for this.

response.sendRedirect(response.encodeRedirectURL("page.jsp"));



回答2:


Without cookies, you have two options. The first is passing a sessionId through Urls. This requires a lot of work on the server because every url you send back must have a sessionId appended to it (usually in the form of a query string parameter). For example:

/path/to/page

becomes

/path/to/page?sessionid=ASDFG-ASDFG-ASDFG-ASDFG-ASDFG

The other option you have would be to combine what information you have via http into a "unique" key and create your own session bucket. By combining the Http UserAgent, RemoteIp and RemoteXfip you can get close to uniquely identifying a user, but there is no guarantees that this key is 100% unique.




回答3:


url rewriting

http://www.developertutorials.com/tutorials/java/implement-session-tracking-050611/page5.html




回答4:


Each URL must be encoded using response.encodeURL("page.jsp")

This will add the Session ID onto the end of each URL so cookies do not have to be enabled.

Note that you will have to do this manually for every single URL in order for it to work.

See this link for more info.



来源:https://stackoverflow.com/questions/1795998/manage-session-when-broswer-has-disable-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!