how can i do sessions in java if some one disables cookies in my browser?

前端 未结 8 1528
长发绾君心
长发绾君心 2020-12-09 12:58

I like to know if someone disables the cookies in my browser then cookies dont work for my browser then how can I do sessions in java. I am writing servlets for server side

8条回答
  •  渐次进展
    2020-12-09 14:01

    You need to append the jsessionid to all the URL's involved in your webapplication which are supposed to be invoked by the client. This includes the redirect URL's and the links in the JSP page.

    In case of a redirect URL, you need to use HttpServletResponse#encodeRedirectURL() first:

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

    In case of links in a JSP page, you basically need to pass those URL's through HttpServletResponse#encodeURL() first. You can do this with help of JSTL's (just drop jstl-1.2.jar in /WEB-INF) tag, it will behind the scenes pass the URL through the aforementioned method:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    ...
        ">link1
        ">link2
        ...
        
    " method="post"> ...

提交回复
热议问题