Overview of Java Web Technologies, Part 1 - Servlet Mapping
(Page 5 of 9 )
Before you can access a servlet from a Web browser, you must map the servlet to a path in your deployment descriptor. For example, the deployment descriptor in Listing 1 creates the servlet name MyServlet and maps it to /aUrl.
Listing 1 The Deployment Descriptor Mapping
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>ch01.MyServlet</servlet-class>
</servlet>
<!–– mapping ––>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/aUrl</url-pattern>
</servlet-mapping>
</web-app>
This enables your users to access the servlet using the following URL:
http://localhost:8080/appName/aUrl
Remember: This is part one of the first chapter of JavaServer Faces Programming, by Budi Kurniawan (McGraw-Hill/Osborne, ISBN 0-07-222983). Stay tuned for part 2 of "Overviews of Java Web Technologies," where we learn about JSP, JavaBeans, and Model 2. Buy this book! |
Next: Defining Context Parameters >>
More Java Articles
More By McGraw-Hill/Osborne