Class AbstractServlet

  • All Implemented Interfaces:
    jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, java.io.Serializable

    public abstract class AbstractServlet
    extends jakarta.servlet.http.HttpServlet
    This class can be used as a base class for a web console plugin. The plugin (servlet) needs to be registered as a servlet service with at least the label property.

    Extending this servlet is one way of providing a plugin. The other is to simply direclty implement the servlet interface. In both cases requests to resources with a path of "LABEL/res/*" are automatically handled.

    For html (content) requests, the web console automatically renders the header, footer and navigation.

    Support for Jakarta servlets requires that the Jakarta Servlet API and the Apache Felix Http Wrappers are available in the runtime.

    If you are upgrading from AbstractWebConsolePlugin there are some changes to be aware of:

    • Resources are detected via the getResource(String) method.
    • Regardless of the http method, if the corresponding doXXX method does not create a response, the renderContent(HttpServletRequest, HttpServletResponse) method is invoked.
    • If a doXXX method other than doGet wants to create a response, it must not call doGet or renderContent directly. It rather just does not create any response and returns. In this case the web console will invoke the renderContent method afterwards.
    See Also:
    ServletConstants.PLUGIN_LABEL, ServletConstants.PLUGIN_TITLE, ServletConstants.PLUGIN_CATEGORY, ServletConstants.PLUGIN_CSS_REFERENCES, Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractServlet()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void renderContent​(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      This method is used to render the main contents of the plugin
      static void setNoCache​(jakarta.servlet.http.HttpServletResponse response)
      Sets response headers to force the client to not cache the response sent back.
      • Methods inherited from class jakarta.servlet.http.HttpServlet

        service
      • Methods inherited from class jakarta.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractServlet

        public AbstractServlet()
    • Method Detail

      • renderContent

        public void renderContent​(jakarta.servlet.http.HttpServletRequest request,
                                  jakarta.servlet.http.HttpServletResponse response)
                           throws jakarta.servlet.ServletException,
                                  java.io.IOException
        This method is used to render the main contents of the plugin
        Parameters:
        request - The request
        response - The response
        Throws:
        jakarta.servlet.ServletException - If an error occurs
        java.io.IOException - If writing the response fails
      • setNoCache

        public static final void setNoCache​(jakarta.servlet.http.HttpServletResponse response)
        Sets response headers to force the client to not cache the response sent back. This method must be called before the response is committed otherwise it will have no effect.

        This method sets the Cache-Control, Expires, and Pragma headers.

        Parameters:
        response - The response for which to set the cache prevention