|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet org.apache.velocity.tools.view.VelocityViewServlet
public class VelocityViewServlet
A servlet to process Velocity templates. This is comparable to the the JspServlet for JSP-based applications.
The servlet provides the following features:
VelocityViewServlet supports the following configuration parameters in web.xml:
true
. If set to false
, then
the VelocityView
used by this servlet will not be shared
with VelocityViewFilter
s, other VelocityViewServlets or
VelocityViewTag
s in the
application.true
. If set to false
, then
the default toolbox configuration will not be added to your (if any)
custom configuration. NOTE: The default configuration will also be
suppressed if you are using a deprecated toolbox.xml format and do not
explicitly set this to true
.false
. If set to true
, then
then the final toolbox configuration (the combination of any custom
one(s) provided by yourself and/or the default configuration(s))
will have all invalid tools, properties, and/or data removed prior to
configuring the ToolboxFactory for this servlet by a
ConfigurationCleaner
HttpServletResponse
's writer. If this parameter is
set to true
, then the output of the merge process will be
buffered before being fed to the response. This allows the error(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Throwable)
method to be overridden to return a "500 Internal Server Error" or
at least not return any of the failed request content. Essentially,
setting this to true
degrades performance in order to enable
a more "correct" error response"
Field Summary | |
---|---|
static java.lang.String |
BUFFER_OUTPUT_PARAM
|
private boolean |
bufferOutput
|
private static long |
serialVersionUID
|
private VelocityView |
view
|
Constructor Summary | |
---|---|
VelocityViewServlet()
|
Method Summary | |
---|---|
protected org.apache.velocity.context.Context |
createContext(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handles GET - calls doRequest() |
void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle a POST request - calls doRequest() |
protected void |
doRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handles with both GET and POST requests |
protected void |
error(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.Throwable e)
Invoked when there is an error thrown in any part of doRequest() processing. |
protected void |
fillContext(org.apache.velocity.context.Context context,
javax.servlet.http.HttpServletRequest request)
|
protected java.lang.String |
findInitParameter(javax.servlet.ServletConfig config,
java.lang.String key)
Looks up an init parameter with the specified key in either the ServletConfig or, failing that, in the ServletContext. |
protected org.apache.velocity.runtime.log.Log |
getLog()
|
protected org.apache.velocity.Template |
getTemplate(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
|
protected org.apache.velocity.Template |
getTemplate(java.lang.String name)
|
protected java.lang.String |
getVelocityProperty(java.lang.String name,
java.lang.String alternate)
|
protected VelocityView |
getVelocityView()
|
protected org.apache.velocity.Template |
handleRequest(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.apache.velocity.context.Context ctx)
This was a common extension point, but now it is usually simpler to override fillContext(org.apache.velocity.context.Context, javax.servlet.http.HttpServletRequest) to add custom things
to the Context or override a getTemplate(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
method to change how Template s are retrieved. |
void |
init(javax.servlet.ServletConfig config)
Initializes servlet and VelocityView used to process requests. |
protected void |
manageResourceNotFound(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.apache.velocity.exception.ResourceNotFoundException e)
Manages the ResourceNotFoundException to send an HTTP 404 result
when needed. |
protected void |
mergeTemplate(org.apache.velocity.Template template,
org.apache.velocity.context.Context context,
javax.servlet.http.HttpServletResponse response)
|
protected void |
requestCleanup(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.apache.velocity.context.Context context)
Cleanup routine called at the end of the request processing sequence allows a derived class to do resource cleanup or other end of process cycle tasks. |
protected void |
setContentType(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Sets the content type of the response. |
protected void |
setVelocityView(VelocityView view)
|
Methods inherited from class javax.servlet.http.HttpServlet |
---|
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
---|
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String BUFFER_OUTPUT_PARAM
private static final long serialVersionUID
private transient VelocityView view
private boolean bufferOutput
Constructor Detail |
---|
public VelocityViewServlet()
Method Detail |
---|
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
Initializes servlet and VelocityView used to process requests. Called by the servlet container on loading.
init
in interface javax.servlet.Servlet
init
in class javax.servlet.GenericServlet
config
- servlet configuation
javax.servlet.ServletException
protected java.lang.String findInitParameter(javax.servlet.ServletConfig config, java.lang.String key)
protected VelocityView getVelocityView()
protected void setVelocityView(VelocityView view)
protected java.lang.String getVelocityProperty(java.lang.String name, java.lang.String alternate)
protected org.apache.velocity.runtime.log.Log getLog()
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
doGet
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
doPost
in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException
protected void doRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
request
- HttpServletRequest object containing client requestresponse
- HttpServletResponse object for the response
java.io.IOException
protected org.apache.velocity.Template handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.velocity.context.Context ctx)
This was a common extension point, but now it is usually
simpler to override fillContext(org.apache.velocity.context.Context, javax.servlet.http.HttpServletRequest)
to add custom things
to the Context
or override a getTemplate(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
method to change how Template
s are retrieved.
This is only recommended for more complicated use-cases.
request
- client requestresponse
- client responsectx
- VelocityContext to fill
protected org.apache.velocity.context.Context createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected void fillContext(org.apache.velocity.context.Context context, javax.servlet.http.HttpServletRequest request)
protected void setContentType(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
The default implementation is :
response.setContentType(getVelocityView().getDefaultContentType());
where defaultContentType is set to the value of the default.contentType
property, or "text/html" if that was not set for the VelocityView
.
request
- servlet request from clientresponse
- servlet reponse to clientprotected org.apache.velocity.Template getTemplate(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected org.apache.velocity.Template getTemplate(java.lang.String name)
protected void mergeTemplate(org.apache.velocity.Template template, org.apache.velocity.context.Context context, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
java.io.IOException
protected void error(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Throwable e)
request
- original HttpServletRequest from servlet container.response
- HttpServletResponse object from servlet container.e
- Exception that was thrown by some other part of process.protected void manageResourceNotFound(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.velocity.exception.ResourceNotFoundException e) throws java.io.IOException
ResourceNotFoundException
to send an HTTP 404 result
when needed.
request
- The request object.response
- The response object.e
- The exception to check.
java.io.IOException
- If something goes wrong when sending the HTTP error.protected void requestCleanup(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.velocity.context.Context context)
request
- servlet request from clientresponse
- servlet responsecontext
- Context that was merged with the requested template
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |