标签:解析 equal 推送 tco contex 通过 根据 多次 let
Cookie cookie1=new Cookie("key1", "zhang"); Cookie cookie2=new Cookie("key2", "li"); response.addCookie(cookie1); response.addCookie(cookie2);
request.getCookies(); 返回的是一个Cookie数组。
//Cookie的遍历与取值、改值 Cookie [] cookies =request.getCookies(); for (Cookie cookie : cookies) { //for循环遍历 if ("username".equals(cookie.getName())) { //通过getName取值 cookie.setValue("lisi"); //通过setValue改值 response.addCookie(cookie); } }
Cookie cookie1=new Cookie("key1", "zhang"); Cookie cookie2=new Cookie("key2", "li"); cookie1.setMaxAge(0); response.addCookie(cookie1); response.addCookie(cookie2);
Cookie cookie1=new Cookie("key1", "zhang"); Cookie cookie2=new Cookie("key2", "li"); cookie1.setMaxAge(0); cookie2.setPath(request.getContextPath()+"/1.jsp"); response.addCookie(cookie1); response.addCookie(cookie2);
//Jsp <form action="${pageContext.request.contextPath}/cookie" method="get"> 用户名:<input type="text" name="username" value=${cookie.value}><br> 密码: <input type="password" name="pwd" ><br> <input type="submit" value="登录"> </form>
//servlet中 Cookie cookie=new Cookie("username", "zhangsan"); response.addCookie(cookie); String username = request.getParameter("username"); String pwd = request.getParameter("pwd"); if (username.equals(cookie.getValue())) { response.sendRedirect(request.getContextPath()+"/1.jsp"); } }
只是简单的模仿一下,只是用于记录这个知识点。
标签:解析 equal 推送 tco contex 通过 根据 多次 let
原文地址:http://www.cnblogs.com/Actexpler-S/p/7359630.html