What the web.xml file can do
By Ramakrishna on Oct 16, 2008 in Java Interview Questions
–> Provide an alias for a servlet class so you can call a servlet using a different name.
–> Enable servlet mapping so you can call a servlet using any URL or URL pattern.
–> Define initialization parameters for a servlet or the entire application.
–> Define error pages for an entire application.
–> Provide security constraints to restrict access to certain web pages and servlets.
There are two method to call the pages either by invoking the Servlet class or by invoking JSP file , They both can be entered in the web.xml as follows.
For Example:-
for servlets
<web-app>
<servlet>
<servlet-name></servlet-name>
<servlet-class></servlet-class>
</servlet>
<servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
for jsps
<servlet>
<servlet-name></servlet-name>
<jsp-file></jsp-file>
</servlet>
<servlet-mapping>
<servlet-name></servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
</web-app>
