There are situation, when you don't want to export your application as a WAR file and have the conventional WAR structure. Or for any other reason you want to avoid using web.xml file. In the following we configure an embedded version of Jetty without using web.xml.
The following code should work with Wicket 1.5 and Jetty 8.
Following is an example of web.xml:
What we need to do is simply configure embedded Jetty to exhibit the same behaviour in case of missing web.xml
Configure Jetty to start WebApplication
The Code above configures Jetty in a manner similar to given web.xml file. Note that we use a ServletHolder which encapsulates both context and class of a servlet. The
ServletHolder is then added to ServletContextHandler which as finally added as the only handler to our Jetty Server.
You may wonder where
WicketServlet came from, since it is not explicitly in web.xml. It is important to note that even if in web.xml there is only a filter defined, jetty needs a servlet to serve the requests.
WicketServlet is an implementation of servlet, which contains
WicketFilter to filter requests. If you want to have more control over
WicketFilter see next part.
As you can see, since we need a servlet to serve the request we just added a
Extra Servlet for static resources
WicketFilter automatically passes the requests, which it cannot (or does not want to) process down the chain. In that case you can simply define another Servlet and add it to
ServletContextHandler. This can be used, for example, if you want to access static data accessible under
/static/ folder of your application:
Using the following code if you haven't already configured Wicket to handle a request such as
localhost:8080/static/js/jquery.js, it will be passed down the handler chain to
resourceServlet and it will retrieve the desired file from
staticPath. For more init parameters see DefaultServlet