Java Reference
In-Depth Information
Note Once the container sets the init params in ServletConfig , the container never reads init param
from the deployment descriptor again, unless the servlet is redeployed.
Context-Init Parameters
Context-init parameters are similar to init parameters. The main difference between the context-init
parameters and init params is that context parameters are available to the entire web app while the
init parameters are available to just the servlet. Listing 2-6 illustrates the context-init parameters in
the web.xml file.
Listing 2-6. Defining Context-Initialization Parameters
<param-name>email </param-name>
<param-value> < /param-value>
The <context-param> element is not nested inside the <servlet> element.
Listing 2-7 illustrates how to get the context-init parameters from your servlet.
Listing 2-7. Getting Context-Initialization Parameters
Every servlet inherits a getServletContext() method. The getServletContext() method returns a
ServletContext object.
In a web application, there are two ways to alter the request flow.
Redirecting the request : The request is redirected to a completely different URL.
The redirect can be done by calling sendRedirect() on the response object.
The redirect is done by the browser.
Dispatching the request : The request is dispatched to another component in the
web app, typically a JSP page. A request dispatch is different from a redirect in
that it does the work on the server side. A RequestDispatcher is called on the
request, and a redirect is called on the response.
Figure 2-17 shows the methods in the RequestDispatcher interface.
Search WWH ::

Custom Search