web.xml explained

The web.xml file is a necessary component of a Java Web Application. This file is located under the WEB-INF folder. This file is used to map/match the URL to a servlet or a page. Just note that the value in <servlet-name> tag matches in <servlet> tag and <servlet-mapping> tag. <servlet-class> would be the Java class, and <url-pattern> would be the URL.

Here’s an example for URL

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">

Here’s an example for a page, in this case a jsp file.

(/*) means any other URL , In this example it would be any other URL after /login



we can also initialize servlet parameters in web.xml. Here’s an example below:


For more information on web.xml, here’s a good tutorial.



3 thoughts on “web.xml explained

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s