当前位置: 首页>>代码示例>>Java>>正文


Java Context.getSessionCookiePath方法代码示例

本文整理汇总了Java中org.apache.catalina.Context.getSessionCookiePath方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getSessionCookiePath方法的具体用法?Java Context.getSessionCookiePath怎么用?Java Context.getSessionCookiePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.catalina.Context的用法示例。


在下文中一共展示了Context.getSessionCookiePath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSessionCookie

import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
 * Creates a new session cookie for the given session ID
 *
 * @param context     The Context for the web application
 * @param sessionId   The ID of the session for which the cookie will be
 *                    created
 * @param secure      Should session cookie be configured as secure
 */
public static Cookie createSessionCookie(Context context,
        String sessionId, boolean secure) {

    SessionCookieConfig scc =
        context.getServletContext().getSessionCookieConfig();

    // NOTE: The priority order for session cookie configuration is:
    //       1. Context level configuration
    //       2. Values from SessionCookieConfig
    //       3. Defaults

    Cookie cookie = new Cookie(
            SessionConfig.getSessionCookieName(context), sessionId);
   
    // Just apply the defaults.
    cookie.setMaxAge(scc.getMaxAge());
    cookie.setComment(scc.getComment());
   
    if (context.getSessionCookieDomain() == null) {
        // Avoid possible NPE
        if (scc.getDomain() != null) {
            cookie.setDomain(scc.getDomain());
        }
    } else {
        cookie.setDomain(context.getSessionCookieDomain());
    }

    // Always set secure if the request is secure
    if (scc.isSecure() || secure) {
        cookie.setSecure(true);
    }

    // Always set httpOnly if the context is configured for that
    if (scc.isHttpOnly() || context.getUseHttpOnly()) {
        cookie.setHttpOnly(true);
    }
   
    String contextPath = context.getSessionCookiePath();
    if (contextPath == null || contextPath.length() == 0) {
        contextPath = scc.getPath();
    }
    if (contextPath == null || contextPath.length() == 0) {
        contextPath = context.getEncodedPath();
    }
    if (context.getSessionCookiePathUsesTrailingSlash()) {
        // Handle special case of ROOT context where cookies require a path of
        // '/' but the servlet spec uses an empty string
        // Also ensure the cookies for a context with a path of /foo don't get
        // sent for requests with a path of /foobar
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
    } else {
        // Only handle special case of ROOT context where cookies require a
        // path of '/' but the servlet spec uses an empty string
        if (contextPath.length() == 0) {
            contextPath = "/";
        }
    }
    cookie.setPath(contextPath);

    return cookie;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:72,代码来源:ApplicationSessionCookieConfig.java

示例2: createSessionCookie

import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
 * Creates a new session cookie for the given session ID
 *
 * @param context
 *            The Context for the web application
 * @param sessionId
 *            The ID of the session for which the cookie will be created
 * @param secure
 *            Should session cookie be configured as secure
 */
public static Cookie createSessionCookie(Context context, String sessionId, boolean secure) {

	SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig();

	// NOTE: The priority order for session cookie configuration is:
	// 1. Context level configuration
	// 2. Values from SessionCookieConfig
	// 3. Defaults

	Cookie cookie = new Cookie(SessionConfig.getSessionCookieName(context), sessionId);

	// Just apply the defaults.
	cookie.setMaxAge(scc.getMaxAge());
	cookie.setComment(scc.getComment());

	if (context.getSessionCookieDomain() == null) {
		// Avoid possible NPE
		if (scc.getDomain() != null) {
			cookie.setDomain(scc.getDomain());
		}
	} else {
		cookie.setDomain(context.getSessionCookieDomain());
	}

	// Always set secure if the request is secure
	if (scc.isSecure() || secure) {
		cookie.setSecure(true);
	}

	// Always set httpOnly if the context is configured for that
	if (scc.isHttpOnly() || context.getUseHttpOnly()) {
		cookie.setHttpOnly(true);
	}

	String contextPath = context.getSessionCookiePath();
	if (contextPath == null || contextPath.length() == 0) {
		contextPath = scc.getPath();
	}
	if (contextPath == null || contextPath.length() == 0) {
		contextPath = context.getEncodedPath();
	}
	if (context.getSessionCookiePathUsesTrailingSlash()) {
		// Handle special case of ROOT context where cookies require a path
		// of
		// '/' but the servlet spec uses an empty string
		// Also ensure the cookies for a context with a path of /foo don't
		// get
		// sent for requests with a path of /foobar
		if (!contextPath.endsWith("/")) {
			contextPath = contextPath + "/";
		}
	} else {
		// Only handle special case of ROOT context where cookies require a
		// path of '/' but the servlet spec uses an empty string
		if (contextPath.length() == 0) {
			contextPath = "/";
		}
	}
	cookie.setPath(contextPath);

	return cookie;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:73,代码来源:ApplicationSessionCookieConfig.java


注:本文中的org.apache.catalina.Context.getSessionCookiePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。