...
Code Block | ||||
---|---|---|---|---|
| ||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.sourceforge.net/" xml:lang="en" lang="en"> |
Wicket Servlet Mapping
Wicket 1.x
It is best to map the servlet as /app/*
instead of /*
. The /app/*
mapping allows static resources to be handled by the webserver as opposed to the wicket servlet.
You may experience difficulties with form POSTs if you map to /*
. For example, if a GET request on a Wicket form produces a URL like http://www.examplehost.com/examplecontext/?wicket:interface=wicket-0:2:3
, you will find that Wicket writes an action="/examplecontext?wicket:interface=wicket-0:2:3:someForm:2:IFormSubmitListener"
attribute to the <form> |<form\>
element. Because of the missing /
before the ?
, the container may not recognise the resulting POST as a request for the Wicket servlet. This behaviour has been observed with:
- Jetty 6
- mod_jk when mounted to accept requests for a subdirectory beneath the root web directory (i.e.
"JkMount /* exampleworker"
works but not"JkMount /examplesubdirectory/* exampleworker"
)
Wicket 2.x
To avoid this issue with Wicket 2.0, the recommandation has been changed to use a ServletFilter rather than a servlet - See the Migrate-2.0 page for details of the changes required.
More info
(Thanks, Igor)
Usually static resources are handled by the application server. The server knows it is serving a file and thus sets the last modified date of the resource to the last modified date of a file.
So, for example, let's say you have /myapp/images/foo.gif
and you map your wicket servlet to /*
What happens is that when a request comes in for /myapp/images/foo.gif
it will match the wicket servlet - so now it is wicket servlet's job to serve this file to the browser. now we are nice enough to provide support for this - but obviously we cannot do as good a job as the application server which has a lot more context.
So for 1.x, we recommend mapping the servlet to something like /app/*
so that foo.gif
will be processed by the application server and only wicket-specific requests are processed by the servlet.
For 2.x, what we do is instead of using a servlet, use a filter.
The advantage of a filter is that, unlike a servlet, it can choose not to process the request and let whatever is next in chain try. So when using a wicket filter and a request comes in for foo.gif
the filter can choose not to process it because it knows it is not a wicket-related request. Since the filter didnt process it, it falls on to the application server to try, and then it works.
Anonymous Inner classes
Don't do this:
...