public abstract class AttributeKey<T> extends Object
Servlet API has a bag of stuff in several scopes (such as request, session, ...) but the API is not type-safe. This object provides a convenient type-safe access to to such bags, as well as providing uniform API regardless of the actual scope.
Each instance of AttributeKey
gets an unique attribute name, which means
in the most typical case, these instances should be used as a singleton.
Constructor and Description |
---|
AttributeKey() |
AttributeKey(String name) |
Modifier and Type | Method and Description |
---|---|
static <T> AttributeKey<T> |
appScoped()
Creates a new
ServletContext -scoped AttributeKey . |
T |
get() |
abstract T |
get(javax.servlet.http.HttpServletRequest req) |
void |
remove() |
abstract void |
remove(javax.servlet.http.HttpServletRequest req) |
static <T> AttributeKey<T> |
requestScoped()
Creates a new request-scoped
AttributeKey . |
static <T> AttributeKey<T> |
sessionScoped()
Creates a new session-scoped
AttributeKey . |
abstract void |
set(javax.servlet.http.HttpServletRequest req,
T value) |
void |
set(T value) |
protected final String name
public AttributeKey()
public AttributeKey(String name)
public abstract T get(javax.servlet.http.HttpServletRequest req)
public abstract void set(javax.servlet.http.HttpServletRequest req, T value)
public abstract void remove(javax.servlet.http.HttpServletRequest req)
public final T get()
public final void set(T value)
public final void remove()
public static <T> AttributeKey<T> requestScoped()
AttributeKey
.public static <T> AttributeKey<T> sessionScoped()
AttributeKey
.public static <T> AttributeKey<T> appScoped()
ServletContext
-scoped AttributeKey
.Copyright © 2016. All rights reserved.