0% found this document useful (0 votes)
47 views5 pages

Unit - 7 (Request Dispatching Methods) Servlet Request Interface

The document discusses request dispatching methods in servlets. It describes how to work with request parameters by getting a single parameter value, an array of values, or enumerating all parameter names. It also explains how to use initialization parameters that are specific to a servlet or shared across servlets, and provides examples. Finally, it describes the RequestDispatcher interface and its methods to forward or include requests to other resources on the server.

Uploaded by

Ravi Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Unit - 7 (Request Dispatching Methods) Servlet Request Interface

The document discusses request dispatching methods in servlets. It describes how to work with request parameters by getting a single parameter value, an array of values, or enumerating all parameter names. It also explains how to use initialization parameters that are specific to a servlet or shared across servlets, and provides examples. Finally, it describes the RequestDispatcher interface and its methods to forward or include requests to other resources on the server.

Uploaded by

Ravi Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

1

Unit -7(Request Dispatching Methods)


Servlet Request Interface:
Working with Request parameters:
The ServletRequest interface provides the following methods to get request parameters:

String getParameter(String name) – Returns the value of a request parameter with the given name as
a String format, or returns null value if the parameter does not exist.

String[] getparameter Values(String name) – returns an array of string objects containing all values
in a request parameter or returns null value if the parameter does not exist.

Enumeration getParameterNames() –Returns an enumeration of string objects containing the names


of the parameters in a request.

Working with Initialization parameters:


Servlet Container provides the ability to store startup and configuration information for a servlet in the
form of initialization parameters , known as init parameters and context init parameters.

Init parameters are specific to Servlet configured in the deployment descriptor file, but the

Context init parameters are specific to all or multiple servlets configured in the deployment
descriptor file.

Need for Initialization parameters:


To minimize the complexity of server side programming and reduce maintenance of web application .

Example 1:

web.xmlfile

<web-app>
<servlet>
<servlet-name>dummy1</servlet-name>
<servlet-class>IniParamDetails</servlet-class>
<init-param>
<param-name>email</param-name>
<param-value>[email protected]</param-value>
</init-param>

</servlet>
<servlet-mapping>
<servlet-name>dummy1</servlet-name>
<url-pattern>/iniparam</url-pattern>
</servlet-mapping>
2

</web-app>

Working with Context parameters:

Context init parameters are specific to all or multiple servlets configured in the deployment
descriptor file.

Example 2:

web.xmlfile

<web-app>
<context-param>
<param-name>email</param-name>
<param-value>[email protected]</param-value>
</context-param>
<servlet>
<servlet-name>dummy1</servlet-name>
<servlet-class>ContextParamDetails1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dummy1</servlet-name>
<url-pattern>/conparam1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>dummy2</servlet-name>
<servlet-class>ContextParamDetails2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dummy2</servlet-name>
<url-pattern>/conparam2</url-pattern>
</servlet-mapping>
</web-app>
3

Describing RequestDispatcher Interface:


RequestDispatcher is an interface, implementation of which defines an object which
can dispatch request to any resources(such as HTML, Image, JSP, Servlet) on the server.

Methods of RequestDispatcher

RequestDispatcher interface provides two important methods

Methods Description

voidforward(ServletRequest request, forwards a request from a servlet to another


ServletResponse response) resource (servlet, JSP file, or HTML file) on the
server

voidinclude(ServletRequest request, includes the content of a resource (servlet, JSP


ServletResponse response) page, HTML file) in the response
4

As you see in the above figure, response of second servlet is sent


to the client. Response of the first servlet is not displayed to the
user.

As you can see in the above figure, response of second servlet is


included in the response of the first servlet that is being sent to
the client.
5

You might also like