Description
The ServletContextObject is a Velocity Context Object for the OpenCms Module "at.infonova.opencms.modules.velocity" from Infonova Gmbh.
OpenCms is a Content Management System that is based on Open Source Software. Complex Intranet and Internet websites can be quickly and cost-effectively created, maintained and managed.
Config
This ContextObject must be configured in "WEB-INF/config/infonova-velocity.xml".
The entry could look like the following:
<opencms>
<velocity>
<velocity-context-objects>
[...]
<velocity-context-object
name="servlet"
factory-class="at.infonova.opencms.modules.velocity.contextobjects.ServletContextObject$Factory" />
</velocity-context-objects>
</velocity>
</opencms>
After configuration the ContextObject a reboot of OpenCms is required.
Example Usage
After configuration the ContextObject it is available in all Velocity templates which are parsed by the OpenCms Module "at.infonova.opencms.modules.velocity" from Infonova Gmbh.
The default prefix of this ContextObject should be 'servlet'.
After that, the following Methods are available:
- ${servlet.help} => This helptext.
- ${servlet.pageContext} => The Velocity PageContext object. Provides an API to access various objects including: 'servletContext', Http-'request', Http-'session'. Example: ${servlet.pageContext.request.requestURI}
- ${servlet.pageScope} => a java.util.Map that maps Velocity-page-scoped attribute names to their values.
- ${servlet.requestScope} => a java.util.Map that maps request-scoped attribute names to their values.
- ${servlet.sessionScope} => a java.util.Map that maps session-scoped attribute names to their values.
- ${servlet.applicationScope} => a java.util.Map that maps application-scoped attribute names to their values.
- ${servlet.param} => a java.util.Map that maps parameter names to a single String parameter value (obtained by calling ServletRequest.getParameter(String name)).
- ${servlet.paramValues} => a java.util.Map that maps parameter names to a String[] of all values for that parameter (obtained by calling ServletRequest.getParameterValues(String name)).
- ${servlet.header} => a java.util.Map that maps header names to a single String header value (obtained by calling HttpServletRequest.getHeader(String name)).
- ${servlet.headerValues} => a java.util.Map that maps header names to a String[] of all values for that header.
- ${servlet.cookie} => a java.util.Map that maps cookie names to a single Cookie object. Cookies are retrieved according to the semantics of HttpServletRequest.getCookies(). If the same name is shared by multiple cookies, an implementation must use the FIRST one encountered in the array of Cookie objects returned by the getCookies() method. However, users of the cookie implicit object must be aware that the ordering of cookies is currently unspecified in the servlet specification.
- ${servlet.initParam} => a java.util.Map that maps context initialization parameter names to their String parameter value (obtained by calling ServletContext.getInitParameter(String name)).