org.apache.struts2.sitemesh

## Class VelocityDecoratorServlet

- java.lang.Object
- - javax.servlet.GenericServlet
  - - javax.servlet.http.HttpServlet
    - - org.apache.velocity.tools.view.VelocityViewServlet
      - - org.apache.struts2.sitemesh.VelocityDecoratorServlet

- All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

      public class VelocityDecoratorServlet
      extends org.apache.velocity.tools.view.VelocityViewServlet

  This is a SiteMesh Velocity view servlet.

  It overrides the SiteMesh servlet to rely on the Velocity Manager in Struts instead of creating it's own manager

  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected String` | `defaultContentType`
    `protected VelocityManager` | `velocityManager`

    - ### Fields inherited from class org.apache.velocity.tools.view.VelocityViewServlet

      `BUFFER_OUTPUT_PARAM`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `VelocityDecoratorServlet()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected org.apache.velocity.context.Context` | `createContext(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Creates and returns an initialized Velocity context.
    `org.apache.velocity.Template` | `handleRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.velocity.context.Context context)`
    `void` | `init(javax.servlet.ServletConfig config)` Initializes servlet, toolbox and Velocity template engine.
    `protected void` | `setContentType(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Sets the content type of the response.

    - ### Methods inherited from class org.apache.velocity.tools.view.VelocityViewServlet

      `doGet, doPost, doRequest, error, fillContext, findInitParameter, getLog, getOutputWriter, getTemplate, getTemplate, getVelocityProperty, getVelocityView, initRequest, manageResourceNotFound, mergeTemplate, mergeTemplate, requestCleanup, setVelocityView`

    - ### 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

    - #### velocityManager

          protected VelocityManager velocityManager

    - #### defaultContentType

          protected String defaultContentType

  - ### Constructor Detail

    - #### VelocityDecoratorServlet

          public VelocityDecoratorServlet()

  - ### Method Detail

    - #### init

          public void init(javax.servlet.ServletConfig config)
                    throws javax.servlet.ServletException

      Initializes servlet, toolbox and Velocity template engine. Called by the servlet container on loading.

      NOTE: If no charset is specified in the default.contentType property (in your velocity.properties) and you have specified an output.encoding property, then that will be used as the charset for the default content-type of pages served by this servlet.

      Specified by:
        `init` in interface `javax.servlet.Servlet`
      Overrides:
        `init` in class `org.apache.velocity.tools.view.VelocityViewServlet`
      Parameters:
        `config` - servlet configuration
      Throws:
        `javax.servlet.ServletException`

    - #### handleRequest

          public org.apache.velocity.Template handleRequest(javax.servlet.http.HttpServletRequest request,
                                                            javax.servlet.http.HttpServletResponse response,
                                                            org.apache.velocity.context.Context context)

      Overrides:
        `handleRequest` in class `org.apache.velocity.tools.view.VelocityViewServlet`

    - #### createContext

          protected org.apache.velocity.context.Context createContext(javax.servlet.http.HttpServletRequest request,
                                                                      javax.servlet.http.HttpServletResponse response)

      Creates and returns an initialized Velocity context.

      Overrides:
        `createContext` in class `org.apache.velocity.tools.view.VelocityViewServlet`
      Parameters:
        `request` - servlet request from client
        `response` - servlet reponse to client

    - #### setContentType

          protected void setContentType(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)

      Sets the content type of the response. This is available to be overridden by a derived class.

      The default implementation is:

              response.setContentType(defaultContentType);

      where defaultContentType is set to the value of the default.contentType property, or "text/html" if that is not set.

      Overrides:
        `setContentType` in class `org.apache.velocity.tools.view.VelocityViewServlet`
      Parameters:
        `request` - servlet request from client
        `response` - servlet reponse to client

Copyright © 2000–2023 Apache Software Foundation. All rights reserved.