SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 71 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

0 " +
"Transitional//EN\">" + "\n" +
"\n" + "" +<br>"Test Servlet 1" + "\n" +
"\n" +
"

" + "Servlet Name: Test1" + "

\n" +
"

URI: " + uri + "

\n" +
"");
}
}
Chapter 2 ?–  Controlling Web Application Behavior with web.xml 44
Defining Custom URLs
To assign a custom URL, you use the servlet-mapping element along with its
servlet-name and url-pattern subelements. The servlet-name element
specifies the name that was assigned to the servlet using the servlet-name subelement
of the servlet element; url-pattern describes a URL relative to the Web
application root. The value of the url-pattern element must begin with either a
slash (/) or an asterisk and period combination (*.).
Core Approach
The value of url-pattern must begin with either / or *..
The specification allows you to map a servlet to a particular custom URL. For example,
here is a simple web.xml excerpt that lets you use the URL http://host/webApp-
Prefix/UrlTest1 to invoke TestServlet1 declared with the name Test1. Figure
2??“1 shows the result of invoking TestServlet1 with the exact-matching URL.

Test1
coreservlets.TestServlet1

Listing 2.2 web.xml (Excerpt showing servlet name)

xmlns:xsi="http://www.


Pages:
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83