Top Description Methods
javax.servlet

public Interface SessionCookieConfig


Class that may be used to configure various properties of cookies used for session tracking purposes.

An instance of this class is acquired by a call to ServletContext#getSessionCookieConfig.

Since
Servlet 3.0

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the cookie comment set via setComment, or null if setComment was never called
getComment
()

Gets the comment that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public String

Returns:

the cookie domain set via setDomain, or null if setDomain was never called
getDomain
()

Gets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public int

Returns:

the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired, or -1 (the default)
getMaxAge
()

Gets the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public String

Returns:

the cookie name set via setName, or null if setName was never called
getName
()

Gets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public String

Returns:

the cookie path set via setPath, or null if setPath was never called
getPath
()

Gets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public boolean

Returns:

true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as HttpOnly, false otherwise
isHttpOnly
()

Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as HttpOnly.

public boolean

Returns:

true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS, and false if they will be marked as secure only if the request that initiated the corresponding session was also secure
isSecure
()

Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS.

public void
setComment(String
the cookie comment to use
comment
)

Sets the comment that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public void
setDomain(String
the cookie domain to use
domain
)

Sets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public void
setHttpOnly(boolean
true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired shall be marked as HttpOnly, false otherwise
httpOnly
)

Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as HttpOnly.

public void
setMaxAge(int
the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.
maxAge
)

Sets the lifetime (in seconds) for the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public void
setName(String
the cookie name to use
name
)

Sets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public void
setPath(String
the cookie path to use
path
)

Sets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

public void
setSecure(boolean
true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired shall be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS, and false if they shall be marked as secure only if the request that initiated the corresponding session was also secure
secure
)

Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as secure.

Method Detail

getCommentback to summary
public String getComment()

Gets the comment that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Returns:String

the cookie comment set via setComment, or null if setComment was never called

See Also
javax.servlet.http.Cookie#getComment()
getDomainback to summary
public String getDomain()

Gets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Returns:String

the cookie domain set via setDomain, or null if setDomain was never called

See Also
javax.servlet.http.Cookie#getDomain()
getMaxAgeback to summary
public int getMaxAge()

Gets the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

By default, -1 is returned.

Returns:int

the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired, or -1 (the default)

See Also
javax.servlet.http.Cookie#getMaxAge
getNameback to summary
public String getName()

Gets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

By default, JSESSIONID will be used as the cookie name.

Returns:String

the cookie name set via setName, or null if setName was never called

See Also
javax.servlet.http.Cookie#getName()
getPathback to summary
public String getPath()

Gets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

By default, the context path of the ServletContext from which this SessionCookieConfig was acquired will be used.

Returns:String

the cookie path set via setPath, or null if setPath was never called

See Also
javax.servlet.http.Cookie#getPath()
isHttpOnlyback to summary
public boolean isHttpOnly()

Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as HttpOnly.

Returns:boolean

true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as HttpOnly, false otherwise

See Also
javax.servlet.http.Cookie#isHttpOnly()
isSecureback to summary
public boolean isSecure()

Checks if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS.

Returns:boolean

true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired will be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS, and false if they will be marked as secure only if the request that initiated the corresponding session was also secure

See Also
javax.servlet.http.Cookie#getSecure(), ServletRequest#isSecure()
setCommentback to summary
public void setComment(String comment)

Sets the comment that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

As a side effect of this call, the session tracking cookies will be marked with a Version attribute equal to 1.

Parameters
comment:String

the cookie comment to use

Exceptions
IllegalStateException:
if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
See Also
javax.servlet.http.Cookie#setComment(String), javax.servlet.http.Cookie#getVersion
setDomainback to summary
public void setDomain(String domain)

Sets the domain name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Parameters
domain:String

the cookie domain to use

Exceptions
IllegalStateException:
if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
See Also
javax.servlet.http.Cookie#setDomain(String)
setHttpOnlyback to summary
public void setHttpOnly(boolean httpOnly)

Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as HttpOnly.

A cookie is marked as HttpOnly by adding the HttpOnly attribute to it. HttpOnly cookies are not supposed to be exposed to client-side scripting code, and may therefore help mitigate certain kinds of cross-site scripting attacks.

Parameters
httpOnly:boolean

true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired shall be marked as HttpOnly, false otherwise

Exceptions
IllegalStateException:
if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
See Also
javax.servlet.http.Cookie#setHttpOnly(boolean)
setMaxAgeback to summary
public void setMaxAge(int maxAge)

Sets the lifetime (in seconds) for the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Parameters
maxAge:int

the lifetime (in seconds) of the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Exceptions
IllegalStateException:
if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
See Also
javax.servlet.http.Cookie#setMaxAge
setNameback to summary
public void setName(String name)

Sets the name that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Note

Changing the name of session tracking cookies may break other tiers (for example, a load balancing frontend) that assume the cookie name to be equal to the default JSESSIONID, and therefore should only be done cautiously.

Parameters
name:String

the cookie name to use

Exceptions
IllegalStateException:
if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
setPathback to summary
public void setPath(String path)

Sets the path that will be assigned to any session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired.

Parameters
path:String

the cookie path to use

Exceptions
IllegalStateException:
if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
See Also
javax.servlet.http.Cookie#setPath(String)
setSecureback to summary
public void setSecure(boolean secure)

Marks or unmarks the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired as secure.

One use case for marking a session tracking cookie as secure, even though the request that initiated the session came over HTTP, is to support a topology where the web container is front-ended by an SSL offloading load balancer. In this case, the traffic between the client and the load balancer will be over HTTPS, whereas the traffic between the load balancer and the web container will be over HTTP.

Parameters
secure:boolean

true if the session tracking cookies created on behalf of the application represented by the ServletContext from which this SessionCookieConfig was acquired shall be marked as secure even if the request that initiated the corresponding session is using plain HTTP instead of HTTPS, and false if they shall be marked as secure only if the request that initiated the corresponding session was also secure

Exceptions
IllegalStateException:
if the ServletContext from which this SessionCookieConfig was acquired has already been initialized
See Also
javax.servlet.http.Cookie#setSecure(boolean), ServletRequest#isSecure()