javax.servlet
Interface ServletRequest

All Known Subinterfaces:
CauchoRequest, HttpServletRequest
All Known Implementing Classes:
AbstractCauchoRequest, AsyncRequest, AsyncRequest, CauchoRequestWrapper, DispatchRequest, ErrorRequest, FastCgiProxy.ProxyRequest, ForwardRequest, HttpProxy.ProxyRequest, HttpServletRequestImpl, HttpServletRequestWrapper, IncludeRequest, LoadBalance.LoadBalanceRequest, LoginRequest, ProxyCacheRequest, ProxyRule.ProxyRequest, RequestAdapter, RequestWrapper, ServletRequestWrapper, SetRequestSecureFilterChain.SecureServletRequestWrapper, StubServletRequest, StubSessionContextRequest

public interface ServletRequest

ServletRequest encapsulates client request data. See HttpServletRequest for HTTP-specific information.

Requests have user-defined attributes. Servlets can communicate to included or forwarded pages using the request attributes. For example, a servlet may calculate results and place them in the request attributes. It may then forward the call to a JSP template to format the result.

Form parameters are retrieved using getParameter


Method Summary
 AsyncContext getAsyncContext()
          Returns the async context for the request
 java.lang.Object getAttribute(java.lang.String name)
          Returns an attribute value.
 java.util.Enumeration<java.lang.String> getAttributeNames()
          Enumerates all attribute names in the request.
 java.lang.String getCharacterEncoding()
          Returns the character encoding of the POSTed data.
 int getContentLength()
          Returns the content length of the data.
 java.lang.String getContentType()
          Returns the request's mime-type.
 DispatcherType getDispatcherType()
          Returns DispatcherType
 ServletInputStream getInputStream()
          Returns an InputStream to retrieve POST data from the request.
 java.lang.String getLocalAddr()
          This call returns the ip of the host actually used to connect to the Resin server, which means that if ipchains, load balancing, or proxying is involved this call does not return the correct host for forming urls.
 java.util.Locale getLocale()
          Returns the request's preferred locale, based on the Accept-Language header.
 java.util.Enumeration<java.util.Locale> getLocales()
          Returns an enumeration of all locales acceptable by the client.
 java.lang.String getLocalName()
          Returns the IP address of the local host, i.e.
 int getLocalPort()
          Returns the port of the local host.
 java.lang.String getParameter(java.lang.String name)
          Returns a form parameter.
 java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
          Returns a Map of the form parameters.
 java.util.Enumeration<java.lang.String> getParameterNames()
          Returns an enumeration of all form parameter names.
 java.lang.String[] getParameterValues(java.lang.String name)
          Returns all values of a form parameter.
 java.lang.String getProtocol()
          Returns the prococol, e.g.
 java.io.BufferedReader getReader()
          Returns a reader to read POSTed data.
 java.lang.String getRealPath(java.lang.String uri)
          Deprecated.  
 java.lang.String getRemoteAddr()
          Returns the IP address of the remote host, i.e.
 java.lang.String getRemoteHost()
          Returns the DNS hostname of the remote host, i.e.
 int getRemotePort()
          Returns the port of the remote host, i.e.
 RequestDispatcher getRequestDispatcher(java.lang.String uri)
          Returns a request dispatcher for later inclusion or forwarding.
 java.lang.String getScheme()
          Returns the request scheme, e.g.
 java.lang.String getServerName()
          Returns the server name handling the request.
 int getServerPort()
          Returns the server port used by the client, e.g.
 ServletContext getServletContext()
          Returns the servlet context for the request
 boolean isAsyncStarted()
          Returns true if the request is in async.
 boolean isAsyncSupported()
          Returns true if the request supports async
 boolean isSecure()
          Returns true if the connection is secure, e.g.
 void removeAttribute(java.lang.String name)
          Removes the given attribute.
 void setAttribute(java.lang.String name, java.lang.Object o)
          Sets an attribute value.
 void setCharacterEncoding(java.lang.String encoding)
          Overrides the character encoding specified in the request.
 AsyncContext startAsync()
          Starts an async/comet mode
 AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse)
          Starts an async mode
 

Method Detail

getProtocol

java.lang.String getProtocol()
Returns the prococol, e.g. "HTTP/1.1"


getScheme

java.lang.String getScheme()
Returns the request scheme, e.g. "http"


getServerName

java.lang.String getServerName()
Returns the server name handling the request. When using virtual hosts, this returns the virtual host name, e.g. "vhost1.caucho.com". This call returns the host name as the client sees it, which means that if ipchains, load balancing, or proxying is involved this call returns the correct call for forming urls, but may not contain the host that Resin is actually listening on.


getServerPort

int getServerPort()
Returns the server port used by the client, e.g. 80. This call returns the port number as the client sees it, which means that if ipchains, load balancing, or proxying is involved this call returns the correct call for forming urls, but may not return the actual port that Resin is listening on. This call should not be used to test for an ssl connection (getServerPort() == 443), isSecure() is provided for that purpose.


getRemoteAddr

java.lang.String getRemoteAddr()
Returns the IP address of the remote host, i.e. the client browser.


getRemoteHost

java.lang.String getRemoteHost()
Returns the DNS hostname of the remote host, i.e. the client browser.


getRemotePort

int getRemotePort()
Returns the port of the remote host, i.e. the client browser.

Since:
2.4

getLocalAddr

java.lang.String getLocalAddr()
This call returns the ip of the host actually used to connect to the Resin server, which means that if ipchains, load balancing, or proxying is involved this call does not return the correct host for forming urls.

Since:
2.4

getLocalName

java.lang.String getLocalName()
Returns the IP address of the local host, i.e. the server. This call returns the name of the host actaully used to connect to the Resin server, which means that if ipchains, load balancing, or proxying is involved this call does not return the correct host for forming urls.

Since:
2.4

getLocalPort

int getLocalPort()
Returns the port of the local host. This call returns the port number actually used to connect to the Resin server, which means that if ipchains, load balancing, or proxying is involved this call does not return the correct port for forming urls. This call should not be used to test for an ssl connection (getServerPort() == 443), isSecure() is provided for that purpose.

Since:
2.4

setCharacterEncoding

void setCharacterEncoding(java.lang.String encoding)
                          throws java.io.UnsupportedEncodingException
Overrides the character encoding specified in the request. setCharacterEncoding must be called before calling getReader or reading any parameters.

Throws:
java.io.UnsupportedEncodingException

getParameter

java.lang.String getParameter(java.lang.String name)
Returns a form parameter. When the form contains several parameters of the same name, getParameter returns the first.

For example, calling getParameter("a") with the the query string a=1&a=2 will return "1".

Parameters:
name - the form parameter to return
Returns:
the form value or null if none matches.

getParameterValues

java.lang.String[] getParameterValues(java.lang.String name)
Returns all values of a form parameter.

For example, calling getParameterValues("a") with the the query string a=1&a=2 will return ["1", "2"].

Parameters:
name - the form parameter to return
Returns:
an array of matching form values or null if none matches.

getParameterNames

java.util.Enumeration<java.lang.String> getParameterNames()
Returns an enumeration of all form parameter names.
 Enumeration e = request.getParameterNames();
 while (e.hasMoreElements()) {
   String name = (String) e.nextElement();
   out.println(name + ": " + request.getParameter(name));
 }
 


getParameterMap

java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
Returns a Map of the form parameters. The map is immutable. The keys are the form keys as returned by getParameterNames and the values are String arrays as returned by getParameterValues.


getInputStream

ServletInputStream getInputStream()
                                  throws java.io.IOException
Returns an InputStream to retrieve POST data from the request. The stream will automatically end when the end of the POST data is complete.

Throws:
java.io.IOException

getReader

java.io.BufferedReader getReader()
                                 throws java.io.IOException,
                                        java.lang.IllegalStateException
Returns a reader to read POSTed data. Character encoding is based on the request data and is the same as getCharacterEncoding()

Throws:
java.io.IOException
java.lang.IllegalStateException

getCharacterEncoding

java.lang.String getCharacterEncoding()
Returns the character encoding of the POSTed data.


getContentLength

int getContentLength()
Returns the content length of the data. This value may differ from the actual length of the data. Newer browsers supporting HTTP/1.1 may use "chunked" encoding which does not make the content length available.

The upshot is, rely on the input stream to end when the data completes.


getContentType

java.lang.String getContentType()
Returns the request's mime-type.


getLocale

java.util.Locale getLocale()
Returns the request's preferred locale, based on the Accept-Language header. If unspecified, returns the server's default locale.


getLocales

java.util.Enumeration<java.util.Locale> getLocales()
Returns an enumeration of all locales acceptable by the client.


isSecure

boolean isSecure()
Returns true if the connection is secure, e.g. it uses SSL.


getAttribute

java.lang.Object getAttribute(java.lang.String name)
Returns an attribute value.

Parameters:
name - the attribute name
Returns:
the attribute value

setAttribute

void setAttribute(java.lang.String name,
                  java.lang.Object o)
Sets an attribute value.

Parameters:
name - the attribute name
o - the attribute value

getAttributeNames

java.util.Enumeration<java.lang.String> getAttributeNames()
Enumerates all attribute names in the request.


removeAttribute

void removeAttribute(java.lang.String name)
Removes the given attribute.

Parameters:
name - the attribute name

getRequestDispatcher

RequestDispatcher getRequestDispatcher(java.lang.String uri)
Returns a request dispatcher for later inclusion or forwarding. This is the servlet API equivalent to SSI includes. uri is relative to the request URI. Absolute URIs are relative to the application prefix (getContextPath()).

If getRequestURI() is /myapp/dir/test.jsp and the uri is "inc.jsp", the resulting page is /myapp/dir/inc.jsp.

   RequestDispatcher disp;
   disp = getRequestDispatcher("inc.jsp?a=b");
   disp.include(request, response);
 

Parameters:
uri - path relative to getRequestURI() (including query string) for the included file.
Returns:
RequestDispatcher for later inclusion or forwarding.

getRealPath

java.lang.String getRealPath(java.lang.String uri)
Deprecated. 

Returns the path of the URI.


getDispatcherType

DispatcherType getDispatcherType()
Returns DispatcherType

Returns:

getServletContext

ServletContext getServletContext()
Returns the servlet context for the request

Since:
Servlet 3.0

startAsync

AsyncContext startAsync()
                        throws java.lang.IllegalStateException
Starts an async/comet mode

Throws:
java.lang.IllegalStateException
Since:
Servlet 3.0

startAsync

AsyncContext startAsync(ServletRequest servletRequest,
                        ServletResponse servletResponse)
                        throws java.lang.IllegalStateException
Starts an async mode

Throws:
java.lang.IllegalStateException
Since:
Servlet 3.0

getAsyncContext

AsyncContext getAsyncContext()
Returns the async context for the request

Since:
Servlet 3.0

isAsyncStarted

boolean isAsyncStarted()
Returns true if the request is in async.

Since:
Servlet 3.0

isAsyncSupported

boolean isAsyncSupported()
Returns true if the request supports async

Since:
Servlet 3.0