CookieUtil.java
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:1k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.common;
- import javax.servlet.http.Cookie;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class CookieUtil {
- public void setCookieValue(HttpServletResponse hsr, String cookiName,
- String cookiValue, int maxAge) {
- Cookie cookie = new Cookie(cookiName, cookiValue);
- cookie.setMaxAge(maxAge);
- hsr.addCookie(cookie);
- }
- public String getCookieValueByName(HttpServletRequest hsr, String cookiName) {
- Cookie[] cookies = hsr.getCookies();
- for (int i = 0; i < cookies.length; i++) {
- Cookie cookie = cookies[i];
- if (cookiName.equals(cookie.getName())) {
- return cookie.getValue();
- }
- }
- return null;
- }
- }