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

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"

jsp

3. The JSP page uses jspInit, not init. The servlet that is automatically
built from a JSP page may already be using the init
method. Consequently, it is illegal to use a JSP declaration to provide
an init method. You must name the method jspInit instead.
To illustrate the process of initializing JSP pages, Listing 2.10 shows a JSP page
called InitPage.jsp that contains a jspInit method and is placed at the top level of the
deployDemo Web page hierarchy. Normally, a URL of http://localhost/deployDemo/
InitPage.jsp would invoke a version of the page that has no access to initialization
parameters and would thus return null for the firstName and emailAddress
parameters. However, the web.xml file (Listing 2.11) assigns a registered name and
then associates that registered name with the URL pattern /InitPage.jsp. As Figure
2??“14 shows, the result is that the normal URL for the JSP page now invokes the version
of the page that has access to the initialization parameters.
Chapter 2 ?–  Controlling Web Application Behavior with web.xml 62
Listing 2.10 InitPage.jsp


JSP Init Test

Init Parameters:



  • First name: <%= firstName %>
  • Email address: <%= emailAddress %>


<%!
private String firstName = "First name is missing.


Pages:
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100