Understanding web.xml in Java Servlets


Used by the Servlet Container (Ex. Tomcat) to handover user's request to a specified class.



Explaining Tags

<web-app>: Starting of the web.xml should be done with this tag.

<servlet>: Details regarding servlets, the name, servlet class.

<servlet-name>: Name of the servlet, used within the servlet again.

<servlet-class>: Servlet class file is specified here. Servlet container passes request to this class. If was written in a package, then it must be like package_name.sub_package.class

<servlet-mapping>: Mapping servlet class and the url of the users request.  Servlet container determines user's request and then forwards it to the class file with the help of servlet name.

<url-pattern>: The pattern (the url) to which the user's request is received.

Posted by at on

Tags: Servlets,