站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题代码段:存取Cookie

代码段:存取Cookie

摘要: 代码段:存取Cookie

</td> </tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="753" border="0"> <tr> <td> </td> </tr> </table>
protected void setCookie(HttpServletResponse response,String cookieName,String value){
Cookie cookie = new Cookie(cookieName, value);

cookie.setPath("/");
response.addCookie(cookie);
}

protected Cookie getCookie(HttpServletRequest request, String name) {
Cookie[] cookies = request.getCookies();
Cookie returnCookie = null;

if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
Cookie thisCookie = cookies[i];

if (thisCookie.getName().equals(name)) {
returnCookie = thisCookie;
break;
}
}
}

return returnCookie;
}</td> </tr> <tr>


↑返回目录
前一篇: 日期处理例
后一篇: 字符串分页代码