從cookie中取資料

isjun26發表於2018-07-04
		//從cookie中取出資料商城使用者名稱密碼  userCookie    記錄你瀏覽過的商品   productCookie
		public class GetCookie_01 extends HttpServlet {
		 
			public void doGet(HttpServletRequest request, HttpServletResponse response)
					throws ServletException, IOException {
				//獲取所有cookie
				Cookie[] cookies = request.getCookies();
				//遍歷cookie
				for(Cookie cookie : cookies){
					//獲取cookie的名字
					String cookieName = cookie.getName();
					System.out.println(cookieName);  //新浪的cookie檔案會傳過來給你嗎?
					/*if("userName".equalsIgnoreCase(cookieName)){
						//獲取cookie 的資料
						System.out.println(cookieName+" : "+ cookie.getValue() );
					}*/
				}
			
			}
		 
			public void doPost(HttpServletRequest request, HttpServletResponse response)
					throws ServletException, IOException {
				doGet(request, response);
			}
		 
		}

相關文章