Class VelocityServlet

  • All Implemented Interfaces:
    Serializable, Servlet, ServletConfig

    public class VelocityServlet
    extends org.apache.velocity.tools.view.servlet.VelocityViewServlet

    Responds with the expansion of a Velocity Template. The template and context references are specified in the request.

    See Also:
    Serialized Form
    • Constructor Detail

      • VelocityServlet

        public VelocityServlet()
    • Method Detail

      • loadConfiguration

        protected org.apache.commons.collections.ExtendedProperties loadConfiguration​(ServletConfig config)
                                                                               throws IOException,
                                                                                      FileNotFoundException
        Called by the VelocityServlet init(). We want to set a set of properties so that templates will be found in the webapp root. This makes this easier to work with as an example, so a new user doesn't have to worry about config issues when first figuring things out
        Overrides:
        loadConfiguration in class org.apache.velocity.tools.view.servlet.VelocityViewServlet
        Throws:
        IOException
        FileNotFoundException
      • handleRequest

        public org.apache.velocity.Template handleRequest​(HttpServletRequest request,
                                                          HttpServletResponse response,
                                                          org.apache.velocity.context.Context ctx)

        main routine to handle a request. Called by VelocityServlet, your responsibility as programmer is to simply return a valid Template

        Overrides:
        handleRequest in class org.apache.velocity.tools.view.servlet.VelocityViewServlet
        Parameters:
        ctx - a Velocity Context object to be filled with data. Will be used for rendering this template
        Returns:
        Template to be used for request
      • escapeVmName

        protected String escapeVmName​(String name)
        Change any characters that Velocity doesn't like in the name to '_' to make a valid Velocity name
        Parameters:
        name - The name to convert.
        Returns:
        The name converted to a valid Velocity name.