本文整理汇总了Java中javax.servlet.http.Cookie.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.getValue方法的具体用法?Java Cookie.getValue怎么用?Java Cookie.getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.Cookie
的用法示例。
在下文中一共展示了Cookie.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueByCookie
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
private static String getValueByCookie(HttpServletRequest request, String name)
{
Cookie cookies[] = request.getCookies();
String value = null;
if(cookies != null)
{
Cookie cookie = null;
for(int i = 0; i < cookies.length; i++)
{
cookie = cookies[i];
if(cookie.getName().equals(name))
{
value = cookie.getValue();
break;
}
}
}
return value;
}
示例2: getValue
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* 根据cookie名称取得参数值
* @param name cookie参数名
* @return 存在返回String,不存在返回null
*/
public String getValue(String name)
{
Cookie cookies[] = request.getCookies();
String value = null;
if(cookies != null)
{
Cookie cookie = null;
for(int i = 0; i < cookies.length; i++)
{
cookie = cookies[i];
if(cookie.getName().equals(name))
{
value = cookie.getValue();
break;
}
}
}
return value;
}
示例3: findCookieByName
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* 获取指定cookies的值 findCookieByName
*
* @param request
* @param name
* @return String
*/
public static String findCookieByName(HttpServletRequest request,
String name) {
Cookie[] cookies = request.getCookies();
if(null == cookies || cookies.length == 0) return null;
String string = null;
try {
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
String cname = cookie.getName();
if (!StringUtils.isBlank(cname) && cname.equals(name)) {
string = cookie.getValue();
}
}
} catch (Exception ex) {
logger.error("获取Cookies发生异常!", ex);
}
return string;
}
示例4: getServerIdFromCookie
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* Locates any specification of which server that issued a
* session. If there is no session or the session isn't mapped
* to a specific server null is returned.
*
* @param cookies The cookies so look for a session in
* @return the server's ID or null if no server is found
*/
private String getServerIdFromCookie(Cookie[] cookies) {
String serverId = null;
if (cookies != null) {
for (int i=0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
if ( isSessionCookie(cookie.getName()) ) {
String value = cookie.getValue();
String id = value.substring(value.indexOf(".")+1);
if (id.startsWith("server")) {
serverId = id;
}
}
}
}
return serverId;
}
示例5: getCookie
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public String getCookie(HttpServletRequest request, String key) {
Cookie[] cookies = request.getCookies();
if (cookies == null) {
return null;
}
for (Cookie cookie : cookies) {
if ((cookie == null) || (cookie.getName() == null)) {
continue;
}
if (cookie.getName().equals(key)) {
return cookie.getValue();
}
}
return null;
}
示例6: getRequestedSessionId
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Override
public String getRequestedSessionId(HttpServletRequest request) {
Cookie[] cookies = request.getCookies();
for (Cookie cookie : cookies) {
if (cookie == null) {
continue;
}
if (!COOKIE_NAME_SESSION.equalsIgnoreCase(cookie.getName())) {
continue;
}
return cookie.getValue();
}
return null;
}
示例7: getCookie
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* 获取 cookie 的值
* @param name 名称
* @return
*/
public String getCookie(String name){
Cookie[] cookies=request.getCookies();
if(cookies != null && cookies.length >0){
for(int i=0;i<cookies.length;i++){
Cookie cookie=cookies[i];
if(cookie.getName().equals(name) && cookie.getValue()!=null){
try {
return URLDecoder.decode(cookie.getValue(),"utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
return null;
}
示例8: getToken
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public String getToken( HttpServletRequest request ) {
/**
* Getting the token from Cookie store
*/
Cookie authCookie = getCookieValueByName( request, AUTH_COOKIE );
if ( authCookie != null ) {
return authCookie.getValue();
}
/**
* Getting the token from Authentication header
* e.g Bearer your_token
*/
String authHeader = request.getHeader(AUTH_HEADER);
if ( authHeader != null && authHeader.startsWith("Bearer ")) {
return authHeader.substring(7);
}
return null;
}
示例9: loadToken
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
@Override
public CsrfTokenBean loadToken(HttpServletRequest request) {
Cookie cookie = WebUtils.getCookie(request, this.cookieName);
if (cookie == null) {
return null;
}
String token = cookie.getValue();
if (!StringUtils.hasLength(token)) {
return null;
}
return new CsrfTokenBean(this.headerName, this.parameterName, token);
}
示例10: getToken
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* 从Request中获取token
* @param request 请求体
* @return token
*/
public String getToken(HttpServletRequest request) {
Cookie authCookie = getCookieValue(request, jwtProperties.getAuthCookie());
if (authCookie != null) {
return authCookie.getValue();
}
String authHeader = request.getHeader(jwtProperties.getAuthHeader());
if (authHeader != null && authHeader.startsWith("bearer ")) {
return authHeader.substring(7);
}
return null;
}
示例11: getCookie
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* 获取cookie
* @param request
* @param name
* @return
*/
public static String getCookie(HttpServletRequest request, String name) {
String value = null;
Cookie[] cookies = request.getCookies();
if (null != cookies) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(name)) {
value = cookie.getValue();
}
}
}
return value;
}
示例12: getUserNameInCookie
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static String getUserNameInCookie(HttpServletRequest request) {
Cookie[] cookies = request.getCookies();
if (cookies != null)
for (Cookie cookie : cookies)
if (ATT_NAME_USER_NAME.equals(cookie.getName()))
return cookie.getValue();
return null;
}
示例13: getCookieUid
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* 获取cookie中的用户id
*
* @param request
* @return
*/
public static Integer getCookieUid(HttpServletRequest request) {
if (null != request) {
Cookie cookie = cookieRaw(WebConst.USER_IN_COOKIE, request);
if (cookie != null && cookie.getValue() != null) {
try {
String uid = Tools.deAes(cookie.getValue(), WebConst.AES_SALT);
return StringUtils.isNotBlank(uid) && Tools.isNumber(uid) ? Integer.valueOf(uid) : null;
} catch (Exception e) {
}
}
}
return null;
}
示例14: getCookieValue
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
public static String getCookieValue(HttpServletRequest request, String cookieName) {
Cookie[] cookies = request.getCookies();
String k = null;
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName())) {
k = (cookie.getValue());
}
}
}
return k;
}
示例15: getClientParameter
import javax.servlet.http.Cookie; //导入方法依赖的package包/类
/**
* Returns status view selection, if any, based on
* parameters, the session or the cookie.
*/
protected final String getClientParameter(final Parameters params, final HttpServletRequest request,
final String parameterName, final String sessionParameterName,
final String cookieName) {
String result = params.getParameterValue(parameterName);
if (!StringUtils.isBlank(result)) {
return result;
}
result = request.getParameter(parameterName);
if (!StringUtils.isBlank(result)) {
return result;
}
final HttpSession session = request.getSession();
result = (String) session.getAttribute(sessionParameterName);
if (!StringUtils.isBlank(result)) {
return result;
}
final Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
final Cookie cookie = cookies[i];
if (!StringUtils.isBlank(cookie.getName())
&& cookie.getName().equals(cookieName)
&& !StringUtils.isBlank(cookie.getValue())) {
result = cookie.getValue();
break;
}
}
}
return result;
}