Class WicketServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.apache.wicket.protocol.http.WicketServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable
Direct Known Subclasses:
ReloadingWicketServlet

public class WicketServlet extends jakarta.servlet.http.HttpServlet
Please use WicketFilter if you require advanced chaining of resources.

Servlet class for all wicket applications. The specific application class to instantiate should be specified to the application server via an init-params argument named "applicationClassName" in the servlet declaration, which is typically in a web.xml file. The servlet declaration may vary from one application server to another, but should look something like this:

 <servlet>
   <servlet-name>MyApplication</servlet-name>
   <servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class>
   <init-param>
     <param-name>applicationClassName</param-name>
     <param-value>com.whoever.MyApplication</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
 </servlet>
 
Note that the applicationClassName parameter you specify must be the fully qualified name of a class that extends WebApplication. If your class cannot be found, does not extend WebApplication or cannot be instantiated, a runtime exception of type WicketRuntimeException will be thrown.

As an alternative, you can configure an application factory instead. This looks like:

 <init-param>
   <param-name>applicationFactoryClassName</param-name>
   <param-value>teachscape.platform.web.wicket.SpringApplicationFactory</param-value>
 </init-param>
 
and it has to satisfy interface IWebApplicationFactory.

The servlet can also be configured to skip certain paths, this is especially useful when the servlet is mapped to /* mapping:

 <init-param>
   <param-name>ignorePaths</param-name>
   <param-value>/images/products/,/documents/pdf/</param-value>
 </init-param>
 

When GET/POST requests are made via HTTP, a WebRequestCycle object is created from the request, response and session objects (after wrapping them in the appropriate wicket wrappers). The RequestCycle's render() method is then called to produce a response to the HTTP request.

If you want to use servlet specific configuration, e.g. using init parameters from the ServletConfigobject, you should override the init() method of GenericServlet. For example:

 public void init() throws ServletException
 {
     ServletConfig config = getServletConfig();
     String webXMLParameter = config.getInitParameter("myWebXMLParameter");
     ...
 

In order to support frameworks like Spring, the class is non-final and the variable webApplication is protected instead of private. Thus subclasses may provide their own means of providing the application object.

Author:
Jonathan Locke, Timur Mehrvarz, Juergen Donnerstag, Igor Vaynberg (ivaynberg), Al Maw
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected WicketFilter
    The WicketFilter where all the handling is done

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Servlet cleanup.
    final void
    doGet(jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse)
    Handles servlet page requests.
    final void
    doPost(jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse)
    Calls doGet with arguments.
    void
    Servlet initialization
    protected WicketFilter
     

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPut, doTrace, getLastModified, init, service, service

    Methods inherited from class jakarta.servlet.GenericServlet

    getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • doGet

      public final void doGet(jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse) throws jakarta.servlet.ServletException, IOException
      Handles servlet page requests.
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Parameters:
      servletRequest - Servlet request object
      servletResponse - Servlet response object
      Throws:
      jakarta.servlet.ServletException - Thrown if something goes wrong during request handling
      IOException
    • doPost

      public final void doPost(jakarta.servlet.http.HttpServletRequest servletRequest, jakarta.servlet.http.HttpServletResponse servletResponse) throws jakarta.servlet.ServletException, IOException
      Calls doGet with arguments.
      Overrides:
      doPost in class jakarta.servlet.http.HttpServlet
      Parameters:
      servletRequest - Servlet request object
      servletResponse - Servlet response object
      Throws:
      jakarta.servlet.ServletException - Thrown if something goes wrong during request handling
      IOException
      See Also:
    • init

      public void init() throws jakarta.servlet.ServletException
      Servlet initialization
      Overrides:
      init in class jakarta.servlet.GenericServlet
      Throws:
      jakarta.servlet.ServletException
    • newWicketFilter

      Returns:
      The wicket filter
    • destroy

      public void destroy()
      Servlet cleanup.
      Specified by:
      destroy in interface jakarta.servlet.Servlet
      Overrides:
      destroy in class jakarta.servlet.GenericServlet