Monday, November 21, 2011

web.xml

Create a file web.xml in your HelloWorld project root directory (i.e. in the same place as .classpath).

Write (or copy/paste) the following:

 <web-app>  
  <servlet>  
   <servlet-name>hello</servlet-name>  
   <servlet-class>org.confucius.HelloWorld</servlet-class>  
  </servlet>  
   
  <servlet-mapping>  
   <servlet-name>hello</servlet-name>  
   <url-pattern>/home</url-pattern>  
  </servlet-mapping>  
 </web-app>  
   


As mentioned before, web.xml is the master specification which tells the Web Server how to run our Application.

Let us understand what it says.

First it tells the Web Server to map the HelloWorld class (servlet) to the friendly name 'hello'

Then it tell the Web Server to redirect any request for the URL /home to the 'hello' servlet.

No comments: