Pages

Thursday, February 21, 2013

Writing the Deployment Descriptor i.e., web.xml for Servlets


Web.xml is the deployment descriptor i.e., it describes all the classes being used in the project. It is the first file checked by the server and if not present then the output is not obtained.


  1. Following is the example syntax of a web.xml.
  2. Root tag to be used is <web-app>….. </web-app>

Sample web.xml to understand:

<web-app>
//Each servlet has a separate <servlet> tag and <servlet-mapping> tag.<servlet>  //unique name given to the servlet.  <servlet-name>sample</servlet-name>  //Class name placed in the classes folder.  <servlet-class>NewExamples</servlet-class></servlet><servlet-mapping>  //Same name as given in <servlet> tag to link the servlet to url path.  <servlet-name>sample</servlet-name>  //URL pattern to open the servlet in the browser i.e., http://localhost:8080/project-name/url-pattern  <url-pattern>/sam</url-pattern></servlet-mapping></web-app>

0 comments:

Post a Comment