How to define and in servlet 3.0’s web.xml-less?

In Servlets 3.0 you don’t need a web.xml for many cases, however, sometimes it’s required or just useful. Your case is just one of them – there is no special annotations to define welcome-file list or error-pages.

Another thing is – would you really like to have them hardcoded? There are some valid use-cases for annotation / programmatic based configuration and for declarative configuration in XML. Moving to Servlets 3.0 doesn’t necessarily means getting rid of web.xml at all cost.

I would find the entries you posted a better example of configuration in XML. Firstly – they can be changed from deployment to deployment and secondly – they affect whole application and not any particular Servlet.

Leave a Comment