Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define <welcome-file-list> and <error-page> in servlet 3.0's web.xml-less?

I have existing web-app which I want to convert into web.xml-less of servlet's 3.0. I've managed to make it working, however there are 2 tags in web.xml which I still don't know the equivalent code in web.xml-less environment.

<welcome-file-list>     <welcome-file>/index.jsp</welcome-file> </welcome-file-list>  <error-page>     <error-code>404</error-code>     <location>/pageNotFound</location> </error-page> 

Any help is appreciated

like image 504
Wins Avatar asked Nov 19 '12 08:11

Wins


People also ask

What is welcome file list in servlet?

A welcome file is the file that is invoked automatically by the server, if you don't specify any file name. By default server looks for the welcome file in following order: welcome-file-list in web.

Which file specifies the welcome files of a Java web site?

The welcome-file element defines the JSP page to be used as the welcome page. The example discussed in Encapsulating Reusable Content Using Tag Files has a welcome file.

Which option in web XML will load the HTML page when the project is started?

The tag <welcome-file-list> is used for specifying the files that needs to be invoked by server by default, if you do not specify a file name while loading the project on browser. Based on the welcome file list, server would look for the myhome.

What is the use of web XML file in Servlet?

web. xml defines mappings between URL paths and the servlets that handle requests with those paths. The web server uses this configuration to identify the servlet to handle a given request and call the class method that corresponds to the request method.


1 Answers

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.

like image 113
Piotr Nowicki Avatar answered Oct 06 '22 05:10

Piotr Nowicki