Class ViewServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.apache.juneau.rest.server.servlet.RestServlet
org.apache.juneau.rest.server.view.ViewServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable
Direct Known Subclasses:
FreemarkerServlet, JspServlet, MustacheServlet, ThymeleafServlet

public abstract class ViewServlet extends RestServlet
Abstract base for the standalone view-servlet companions of the view mixin resources.

Each per-engine bridge module (juneau-rest-server-view-jsp, juneau-rest-server-view-freemarker, juneau-rest-server-view-mustache, juneau-rest-server-view-thymeleaf) ships a thin Basic*Servlet subclass that:

  1. Declares its own sibling top-level mount via @Rest(paths) (e.g. "/jsp/*"), so the servlet is registered as a sibling of the host application's other servlets (/rest/*, /jsp/*, ...) rather than composed under a host root.
  2. Supplies the per-engine RawTemplateDispatcher (the matching flavor-neutral <Engine>Dispatcher worker) via dispatcher().

The single greedy op declared here (@RestGet(path="/*")) captures the trailing remainder under the servlet's mount and delegates straight to the shared RawTemplateDispatcher. Because the mixin and standalone forms both route through the same RawTemplateDispatcher implementation, their raw file-serving behavior cannot drift.

Standalone vs mixin:

The mixin Basic*Resource keeps its op pinned at /<token>/* for composition into a host at /; the standalone Basic*Servlet moves the mount to the class level (@Rest(paths="/<token>/*")) and pins the op at /*, eliminating the path-doubling that a mixin-shaped op would otherwise produce when the servlet itself is mounted at /<token>/*.

See Also:
Since:
10.0.0
  • Constructor Details

  • Method Details

    • dispatcher

      protected abstract RawTemplateDispatcher dispatcher()
      Returns the per-engine RawTemplateDispatcher this servlet delegates raw template dispatch to.

      Typically the matching flavor-neutral <Engine>Dispatcher worker (which implements RawTemplateDispatcher). Never null.

      Returns:
      The raw-template dispatcher. Never null.
    • render

      public void render(@Path("/*") String path, RestRequest req, RestResponse res) throws IOException
      [GET /*] — render the raw template identified by the trailing path under this servlet's sibling top-level mount.

      The @Path("/*") String path captures the multi-segment remainder after the mount prefix (e.g. a request for /jsp/admin/dashboard.jsp on a servlet mounted at /jsp/* matches with path = "admin/dashboard.jsp"). Delegates verbatim to the shared RawTemplateDispatcher.

      Parameters:
      path - The trailing path segment after the mount prefix.
      req - The current REST request.
      res - The current REST response.
      Throws:
      IOException - If the underlying response writer fails.