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 84 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"


Initializing JSP pages is discussed in the next subsection.
??? Default URLs. Initialization parameters are only available when
servlets are accessed through custom URL patterns associated with
their registered names. So, in this example, the firstName and
emailAddress init parameters would be available when you used the
URL http://host/webAppPrefix/showInitValues, but not when you used
the URL http://host/webAppPrefix/servlet/coreservlets.InitServlet.
Core Warning
Initialization parameters are not available in servlets that are accessed by
their default URL.
Chapter 2 ?–  Controlling Web Application Behavior with web.xml 58
For example, Listing 2.8 shows a simple servlet called InitServlet that
uses the init method to set the firstName and emailAddress fields. Listing
2.9 shows the excerpt from the web.xml file that assigns the custom URL pattern
/showInitValues to the servlet. Figures 2??“12 and 2??“13 show the results when the
servlet is accessed with the custom URL (correct) and the default URL (incorrect),
respectively.
It is simply too hard to remember which URL works and which doesn??™t. In real
Web apps, disable the invoker servlet so that there is only one URL for each servlet.
Reserve the invoker servlet exclusively for quick tests of capabilities in separate
(test-only) Web applications.
Listing 2.8 InitServlet.java
package coreservlets;
import java.io.*;
import javax.


Pages:
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96