本文介绍如何操作Servlet中的Cookie。
获取Request中的Cookie
1 | public static String getCookie(final HttpServletRequest request, final String name){ |
往Response中写入Cookie
1 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
转换httpClient中的Cookie
httpClient中的Cookie操作,参考利用httpClient进行https访问,httpClient中的Cookie和servlet中的Cookie类型不同,需要进行转换:
1 | private static Cookie servletCookieFromApacheCookie(org.apache.http.cookie.Cookie apacheCookie) { |