3.3 Configure the Application Deployment Descriptor - "web.xml"
A web user invokes a servlet, which is kept in the web server, by issuing a specific URL from the browser. In this example, we shall configure the following request URL to trigger the "HelloServlet
":
http://hostname:port/helloservlet/sayhello
Create a configuration file called "web.xml
", and save it under "webapps\helloservlet\WEB-INF
", as follows:
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
- The "
web.xml
" is called web application deployment descriptor. It provides the configuration options for that particular web application, such as defining the the mapping between URL and servlet class. - The above configuration defines a servlet named "
HelloWroldServlet
", implemented in "mypkg.HelloServlet.class
" (written earlier), and maps to URL "/sayhello
", where "/
" denotes the context root of this webapp "helloservlet
". In other words, the absolute URL for this servlet ishttp://hostname:port/helloservlet/sayhello
. - Take note that EACH servlet requires a pair of
<servlet>
and<servlet-mapping>
elements to do the mapping, via an arbitrary but unique<servlet-name>
. Furthermore, all the<servlet>
elements must be grouped together and placed before the<servlet-mapping>
elements (as specified in the XML schema).
https://www.ntu.edu.sg/home/ehchua/programming/java/JavaServlets.html