Servlet::ServletRequest - servlet request interface
for my $name ($request->getAttributeNames()) {
my $val = $request->getAttribute($name);
$request->removeAttribute($name);
# or
$request->setAttribute($name, $newValue);
}
my $encoding = $request->getCharacterEncoding(); $request->setCharacterEncoding($newEncoding);
my $length = $request->getContentLength();
my $type = $request->getContentType();
# gets request body as binary data my $input = $request->getInputStream();
# gets preferred locale my $locale = $request->getLocale();
# gets all locales in descending order of preference my @locales = $request->getLocales();
my %paramMap = $request->getParameterMap();
for my $name ($request->getParameterNames()) {
my $val = $request->getParameter($name);
# or
my @vals = $request->getParameterValues($name);
}
my $protocol = $request->getProtocol();
# gets request body as character data, converted from bytes using # the request's character encoding my $reader = $request->getReader();
my $addr = $request->getRemoteAddr();
my $host = $request->getRemoteHost();
# get a request dispatcher in order to do an include or forward my $dispatcher = $request->getRequestDispatcher($path);
my $server = $request->getServerName();
my $port = $request->getServerPort();
my $flag = $request->isSecure();
This interface defines an object that provides client request
information to a servlet. The servlet container creates a request
object and passes it as an argument to the servlet's service()
method.
A Servlet::ServletRequest object provides data including parameter name and values, attributes, and an input stream. Interfaces that extend ServletRequest can provide additional protocol-specific data (for example, HTTP data is provided by Servlet::Http::HttpServletRequest.
getAttribute($name)Attributes can be set two ways. The servlet container may set
attributes to make available custom information about a request. For
example, for requests made using HTTPS, the attribute
Servlet::Request::X509Certificate can be used to retrieve
information on the certificate of the client. Attributes can also be
set programatically using setAttribute(). This allows information
to be embedded into a request before a Servlet::RequestDispatcher
call.
Attribute names should follow the same convention as package names. The Servlet API specification reserves names matching main::*, CORE::*, UNIVERSAL::*, and any other standard reserved package names.
Parameters:
getAttributeNames()getCharacterEncoding()getContentLength()getContentType()getInputStream()getReader()
may be called to read the body, not both.
Throws:
getReader() method has already been called for this request
getLocale()getLocales()getParameter($name)You should only use this method when you are sure the parameter has
only one value. If the parameter might have more than one value, use
getParameterValues().
If you use this method with a multivalued parameter, the value
returned is equal to the first value in the array returned by
getParameterValues().
If the parameter data was sent in the request body, such as occurs
with an HTTP POST request, then reading the body directly via
getInputStream() or getReader() can interfere with the execution
of this method.
Parameters:
getParameterMap()See getParameter() for more information about parameters and usage.
getParameterNames()See getParameter() for more information about parameters and usage.
getParameterValues($name)If the parameter has a single value, the array has a length of 1. If the parameter has no value, the array is empty.
See getParameter() for more information about parameters and usage.
Parameters:
getProtocol()getReader()getInputStream() may be called to read the body, not both.
Throws:
getInputStream() method has already been called for this
request
getRemoteAddr()getRemoteHost()getRequestDispatcher($path)The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a ``/'', it is interpreted as relative to the current context root. This method returns undef if the servlet cannot return a dispatcher.
The difference between this method and the one provided by Servlet::ServletContext is that this method can take a relative path.
Parameters:
getScheme()getServerName()getServerPort()isSecure()removeAttribute($name)See getAttribute() for information about allowable attribute names.
Parameters:
See getAttribute() for information about allowable attribute names.
Parameters:
setCharacterEncoding($name)getReader().
Parameters:
Throws:
the Servlet::RequestDispatcher manpage, the Servlet::ServletInputStream manpage
Brian Moseley, bcm@maz.org