类 ViewToolContext
- 所有已实现的接口:
org.apache.velocity.context.Context,ViewContext
ToolContext implementation specific to the servlet environment.
It provides the following special features:
- puts the request, response, session, and servlet context objects into the Velocity context for direct access, and keeps them read-only
- supports a read-only toolbox of view tools
- auto-searches servlet request attributes, session attributes and servlet context attribues for objects
The get(String key) method implements the following search order
for objects:
- tool in a request scoped toolbox
- tool in a session scoped toolbox
- tool in a application scoped toolbox
- request, response, session, or servlet context
- object in the local map of objects (traditional use)
- request attributes, session attributes, servlet context attributes
The purpose of this class is to make it easy for web designer to work with Java servlet based web applications. They do not need to be concerned with the concepts of request, session or application attributes and the lifetime of objects in these scopes.
Note that the put() method always puts objects into the local map and does not allow tools or servlet classes to be overridden.
- 版本:
- $Id: ViewContext.java 514727 2007-03-05 16:49:03Z nbubna $
- 作者:
- Geir Magnusson Jr., Gabe Sidler, Nathan Bubna
-
字段概要
从类继承的字段 org.apache.velocity.tools.ToolContext
CATCH_EXCEPTIONS_KEY, CONTEXT_KEY, ENGINE_KEY, LOCALE_KEY, LOG_KEY, PATH_KEY, TOOLKEY_KEY从接口继承的字段 org.apache.velocity.tools.view.ViewContext
APPLICATION, DEFAULT_TOOLBOX_KEY, REQUEST, RESPONSE, SERVLET_CONTEXT_KEY, SESSION -
构造器概要
构造器构造器说明ViewToolContext(org.apache.velocity.app.VelocityEngine velocity, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.ServletContext application) -
方法概要
修饰符和类型方法说明protected voidaddToolboxesUnderKey(String toolboxKey) booleancontainsKey(String key) Indicates whether the specified key is in the context.Looks up and returns the object with the specified key.getAttribute(String key) Searches for the named attribute in request, session (if valid), and application scope(s) in order and returns the value associated or null.jakarta.servlet.http.HttpServletRequestjakarta.servlet.http.HttpServletResponseprotected ObjectgetServletApi(String key) Returns the current matching servlet request, response, session, or servlet context instance, or null if the key matches none of those keys.jakarta.servlet.ServletContextjakarta.servlet.http.HttpSessionprotected ObjectgetToolVar(String key) Finds the automatically provided values, either configured tools or servlet API objects (request, response, etc).protected ObjectgetUserVar(String key) Finds "user" set values, either in the local context or in the scoped attributes if none is in the local context.org.apache.velocity.context.Contextorg.apache.velocity.app.VelocityEngineprotected voidprotected voidsetToolboxKey(String key) 从类继承的方法 org.apache.velocity.tools.ToolContext
addToolbox, findTool, getKeys, getToolbox, getToolClassMap, getToolProperties, getUserCanOverwriteTools, internalGet, keySet, put, putAll, putToolProperties, putToolProperty, putVelocityEngine, remove, setUserCanOverwriteTools
-
构造器详细资料
-
ViewToolContext
public ViewToolContext(org.apache.velocity.app.VelocityEngine velocity, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.ServletContext application)
-
-
方法详细资料
-
setToolboxKey
-
putToolProperties
protected void putToolProperties() -
getToolboxes
- 覆盖:
getToolboxes在类中ToolContext
-
addToolboxesUnderKey
-
get
Looks up and returns the object with the specified key.
See the class documentation for more details.
- 指定者:
get在接口中org.apache.velocity.context.Context- 覆盖:
get在类中ToolContext- 参数:
key- the key of the object requested- 返回:
- the requested object or null if not found
- 另请参阅:
-
getUserVar
Finds "user" set values, either in the local context or in the scoped attributes if none is in the local context.- 参数:
key- attribute name- 返回:
- found value or null
- 另请参阅:
-
getToolVar
Finds the automatically provided values, either configured tools or servlet API objects (request, response, etc).- 参数:
key- attribute key- 返回:
- found configured value or null
- 另请参阅:
-
getServletApi
Returns the current matching servlet request, response, session, or servlet context instance, or null if the key matches none of those keys.- 参数:
key- attribute key- 返回:
- found value or null
-
getAttribute
Searches for the named attribute in request, session (if valid), and application scope(s) in order and returns the value associated or null.
- 指定者:
getAttribute在接口中ViewContext- 参数:
key- attribute key- 返回:
- found value or null
- 从以下版本开始:
- VelocityTools 1.1
-
getRequest
public jakarta.servlet.http.HttpServletRequest getRequest()- 指定者:
getRequest在接口中ViewContext- 返回:
- the current servlet request.
-
getResponse
public jakarta.servlet.http.HttpServletResponse getResponse()- 指定者:
getResponse在接口中ViewContext- 返回:
- the current servlet response.
-
getSession
public jakarta.servlet.http.HttpSession getSession()- 返回:
- the current session, if any.
-
getServletContext
public jakarta.servlet.ServletContext getServletContext()- 指定者:
getServletContext在接口中ViewContext- 返回:
- the servlet context.
-
getVelocityContext
public org.apache.velocity.context.Context getVelocityContext()- 指定者:
getVelocityContext在接口中ViewContext- 返回:
- a reference to the Velocity context (this object).
-
getVelocityEngine
public org.apache.velocity.app.VelocityEngine getVelocityEngine()- 指定者:
getVelocityEngine在接口中ViewContext- 返回:
- a reference to the VelocityEngine.
-
containsKey
Indicates whether the specified key is in the context.- 指定者:
containsKey在接口中org.apache.velocity.context.Context- 覆盖:
containsKey在类中ToolContext- 参数:
key- The key to look for.- 返回:
- Whether the key is in the context.
-