3.2.3.2  Adding the Servlet to the Repository 
Create a new directory under the src/ directory with the name Rectangle. The directory name 
must be the same as the package name specified in the first line of code of the servlet. Then, 
save the Servlet code presented in Section 3.1.3 under its class name (DrawRectangle.java) in 
the Rectangle directory. Schedule the new directory (this is important: always add directories to 
the repository as well!) and the new file for addition to the CVS repository. 
$ cd src
$ mkdir Rectangle
$ cvs add Rectangle
$ cd Rectangle
$ cvs add DrawRectangle.java
3.2.3.3  Registering the Servlet in web.xml 
Before the new servlet can be executed, it needs to be registered in the Web Application 
Deployment Descriptor web.xml. 
To do this, add the following lines to the web.xml file: 
DrawRectangle
Rectangle.DrawRectangle
DrawRectangle
draw_rectangle.servlet
The  tag defines a new servlet. You must provide a servlet name, which can be chosen 
arbitrarily (it does not necessarily have to be the servlet class name). The  
attribute tells the servlet engine where to find the java class file that contains the servlet byte 
code. Last but not least, you need to define the servlet mapping. (The URL that is received 
through the browser request is mapped to a Java class by the servlet engine). 
A servlet mapping should be provided for each servlet. You may also use wildcards for the URL 
patterns. E.g. *.servlet  would map all URL's ending with .servlet to 
the specified servlet name. 
39 




Java Web Hosting Application Development Using Java Technologies Hosting




 
TotalRoute.net Business web hosting division of Vision Web Hosting Inc. All rights reserved.