|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--lindhorst.servlet.http.MultipartRequest
Other than the normal HttpServletRequest class contained in Sun's Servlet
Development Kit, this class handles requests with content type
"multipart/form-data". However it does only partly implement RFC 1867,
since it cannot handle more than one file per parameter (no content type
"multipart/mixed" in parameters).
Since it implements interface HttpServletRequest it can be used instead of the normal
HttpServletRequest that server hands over to the service method of class HttpServlet.
Example:
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
if(req.getContentType().toLowerCase().equals("multipart/form-data"))
req=new MultipartRequest(req);
//do something with it
}
With these lines multipart/form-data requests can be handled just like normal ones.
The only difference is that parameters have to be tested if they hold content or
text and treat them accordingly. See methods isContentParameter() and isNormalParameter().
| Field Summary |
| Fields inherited from interface javax.servlet.http.HttpServletRequest |
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH |
| Constructor Summary | |
MultipartRequest(javax.servlet.http.HttpServletRequest request)
creates a new MultipartRequest instance from the given HttpServletRequest with the default maximum allowed size. |
|
MultipartRequest(javax.servlet.http.HttpServletRequest request,
int maximumSize)
creates a new MultipartRequest instance from the given HttpServletRequest with the given maximum allowed size. |
|
| Method Summary | |
java.lang.Object |
getAttribute(java.lang.String name)
Returns the value of the named attribute of the request, or null if the attribute does not exist. |
java.util.Enumeration |
getAttributeNames()
|
java.lang.String |
getAuthType()
Gets the authentication scheme of this request. |
java.lang.String |
getBoundary()
the boundary returned by this method is the boundary extracted from the original request plus a leading "--" |
java.lang.String |
getCharacterEncoding()
Returns the character set encoding for the input of this request. |
int |
getContentLength()
Returns the size of the request entity data, or -1 if not known. |
java.lang.String |
getContentType()
Returns the Internet Media Type of the request entity data, or null if not known. |
java.lang.String |
getContextPath()
|
javax.servlet.http.Cookie[] |
getCookies()
Gets the array of cookies found in this request. |
long |
getDateHeader(java.lang.String name)
Gets the value of the requested date header field of this request. |
java.lang.String |
getHeader(java.lang.String name)
Gets the value of the requested header field of this request. |
java.util.Enumeration |
getHeaderNames()
Gets the header names for this request. |
java.util.Enumeration |
getHeaders(java.lang.String name)
|
javax.servlet.ServletInputStream |
getInputStream()
Returns an input stream for reading binary data in the request body. |
int |
getIntHeader(java.lang.String name)
Gets the value of the specified integer header field of this request. |
java.util.Locale |
getLocale()
|
java.util.Enumeration |
getLocales()
|
java.lang.String |
getMethod()
Gets the HTTP method (for example, GET, POST, PUT) with which this request was made. |
java.lang.String |
getParameter(java.lang.String parameterName)
Returns a string containing the lone value of the specified parameter, or null if the parameter does not exist. |
byte[] |
getParameterContent(java.lang.String parameterName)
|
java.lang.String |
getParameterContentFileName(java.lang.String parameterName)
|
java.lang.String |
getParameterContentType(java.lang.String parameterName)
|
java.util.Map |
getParameterMap()
|
java.util.Enumeration |
getParameterNames()
Returns the parameter names for this request as an enumeration of strings, or an empty enumeration if there are no parameters or the input stream is empty. |
java.lang.String[] |
getParameterValues(java.lang.String parameterName)
Returns the values of the specified parameter for the request as an array of strings, or null if the named parameter does not exist. |
java.lang.String |
getPathInfo()
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string. |
java.lang.String |
getPathTranslated()
Gets any optional extra path information following the servlet path of this request's URI, but immediately preceding its query string, and translates it to a real path. |
java.lang.String |
getProtocol()
Returns the protocol and version of the request as a string of the form <protocol>/<major version>. |
java.lang.String |
getQueryString()
Gets any query string that is part of the HTTP request URI. |
byte[] |
getRawData()
|
java.io.BufferedReader |
getReader()
Returns a buffered reader for reading text in the request body. |
java.lang.String |
getRealPath(java.lang.String path)
Applies alias rules to the specified virtual path and returns the corresponding real path, or null if the translation can not be performed for any reason. |
java.lang.String |
getRemoteAddr()
Returns the IP address of the agent that sent the request. |
java.lang.String |
getRemoteHost()
Returns the fully qualified host name of the agent that sent the request. |
java.lang.String |
getRemoteUser()
Gets the name of the user making this request. |
javax.servlet.RequestDispatcher |
getRequestDispatcher(java.lang.String path)
|
java.lang.String |
getRequestedSessionId()
Gets the session id specified with this request. |
java.lang.String |
getRequestURI()
Gets, from the first line of the HTTP request, the part of this request's URI that is to the left of any query string. |
java.lang.StringBuffer |
getRequestURL()
|
java.lang.String |
getScheme()
Returns the scheme of the URL used in this request, for example "http", "https", or "ftp". |
java.lang.String |
getServerName()
Returns the host name of the server that received the request. |
int |
getServerPort()
Returns the port number on which this request was received. |
java.lang.String |
getServletPath()
Gets the part of this request's URI that refers to the servlet being invoked. |
javax.servlet.http.HttpSession |
getSession()
|
javax.servlet.http.HttpSession |
getSession(boolean create)
Gets the current valid session associated with this request, if create is false or, if necessary, creates a new session for the request, if create is true. |
java.security.Principal |
getUserPrincipal()
|
boolean |
isContentParameter(java.lang.String parameterName)
|
boolean |
isNormalParameter(java.lang.String parameterName)
|
boolean |
isRequestedSessionIdFromCookie()
Checks whether the session id specified by this request came in as a cookie. |
boolean |
isRequestedSessionIdFromUrl()
Checks whether the session id specified by this request came in as part of the URL. |
boolean |
isRequestedSessionIdFromURL()
|
boolean |
isRequestedSessionIdValid()
Checks whether this request is associated with a session that is valid in the current session context. |
boolean |
isSecure()
|
boolean |
isUserInRole(java.lang.String role)
|
void |
removeAttribute(java.lang.String name)
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
|
void |
setCharacterEncoding(java.lang.String encoding)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public MultipartRequest(javax.servlet.http.HttpServletRequest request)
throws java.io.IOException
request - the original HttpServletRequest
java.io.IOException - if parts needed to process the request have not been included in it or maximum size has been exceeded
public MultipartRequest(javax.servlet.http.HttpServletRequest request,
int maximumSize)
throws java.io.IOException
request - the original HttpServletRequestmaximumSize - the new maximum allowed size for content length
java.io.IOException - if parts needed to process the request have not been included in it or maximum size has been exceeded| Method Detail |
public java.lang.String getBoundary()
public java.lang.String getParameter(java.lang.String parameterName)
getParameter in interface javax.servlet.ServletRequestgetParameterValues(java.lang.String)public java.lang.String[] getParameterValues(java.lang.String parameterName)
getParameterValues in interface javax.servlet.ServletRequestServletRequest.getParameter(java.lang.String)public byte[] getParameterContent(java.lang.String parameterName)
parameterName - the name of the parameter
public java.lang.String getParameterContentType(java.lang.String parameterName)
parameterName - the name of the parameter
public java.lang.String getParameterContentFileName(java.lang.String parameterName)
parameterName - the name of the parameter
public boolean isNormalParameter(java.lang.String parameterName)
parameterName - the name of the parameter
public boolean isContentParameter(java.lang.String parameterName)
parameterName - the name of the parameter
public java.util.Enumeration getParameterNames()
getParameterNames in interface javax.servlet.ServletRequestpublic javax.servlet.http.Cookie[] getCookies()
getCookies in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getMethod()
getMethod in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getRequestURI()
First line of HTTP request Return from getRequestURIPOST /some/path.html HTTP/1.1 /some/path.html GET http://foo.bar/a.html HTTP/1.0 http://foo.bar/a.html HEAD /xyz?a=b HTTP/1.1 /xyz
To reconstruct a URL with a URL scheme and host, use the method javax.servlet.http.HttpUtils.getRequestURL, which returns a StringBuffer.
getRequestURI in interface javax.servlet.http.HttpServletRequestHttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest)public java.lang.String getServletPath()
getServletPath in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getPathInfo()
getPathInfo in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getPathTranslated()
getPathTranslated in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getQueryString()
getQueryString in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getRemoteUser()
getRemoteUser in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getAuthType()
getAuthType in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getHeader(java.lang.String name)
getHeader in interface javax.servlet.http.HttpServletRequestname - the String containing the name of the requested
header field
public int getIntHeader(java.lang.String name)
getIntHeader in interface javax.servlet.http.HttpServletRequestname - the String containing the name of the requested
header field
public long getDateHeader(java.lang.String name)
getDateHeader in interface javax.servlet.http.HttpServletRequestname - the String containing the name of the requested
header field
public java.util.Enumeration getHeaderNames()
getHeaderNames in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.HttpSession getSession(boolean create)
Note: to ensure the session is properly maintained, the servlet developer must call this method (at least once) before any output is written to the response.
Additionally, application-writers need to be aware that newly
created sessions (that is, sessions for which
HttpSession.isNew returns true) do not have any
application-specific state.
getSession in interface javax.servlet.http.HttpServletRequestpublic javax.servlet.http.HttpSession getSession()
getSession in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getRequestedSessionId()
getRequestedSessionId in interface javax.servlet.http.HttpServletRequestisRequestedSessionIdValid()public boolean isRequestedSessionIdValid()
getSession method.
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequestgetRequestedSessionId(),
HttpSessionContext,
getSession(boolean)public boolean isRequestedSessionIdFromCookie()
getSession method.)
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequestgetSession(boolean)public boolean isRequestedSessionIdFromUrl()
getSession method.)
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequestgetSession(boolean)public int getContentLength()
getContentLength in interface javax.servlet.ServletRequestpublic java.lang.String getContentType()
getContentType in interface javax.servlet.ServletRequestpublic java.lang.String getProtocol()
<protocol>/<major version>.<minor
version>. Same as the CGI variable SERVER_PROTOCOL.
getProtocol in interface javax.servlet.ServletRequestpublic java.lang.String getScheme()
getScheme in interface javax.servlet.ServletRequestpublic java.lang.String getServerName()
getServerName in interface javax.servlet.ServletRequestpublic int getServerPort()
getServerPort in interface javax.servlet.ServletRequestpublic java.lang.String getRemoteAddr()
getRemoteAddr in interface javax.servlet.ServletRequestpublic java.lang.String getRemoteHost()
getRemoteHost in interface javax.servlet.ServletRequestpublic java.lang.String getRealPath(java.lang.String path)
getRealPath in interface javax.servlet.ServletRequestpath - the virtual path to be translated to a real path
public javax.servlet.ServletInputStream getInputStream()
throws java.io.IOException
getInputStream in interface javax.servlet.ServletRequestjava.lang.IllegalStateException - if getReader has been
called on this same request.
java.io.IOException - on other I/O related errors.getReader()public java.lang.Object getAttribute(java.lang.String name)
| Attribute Name | Attribute Type | Description |
|---|---|---|
| javax.net.ssl.cipher_suite | string | The string name of the SSL cipher suite in use, if the request was made using SSL |
| javax.net.ssl.peer_certificates | array of javax.security.cert.X509Certificate | The chain of X.509 certificates which authenticates the client. This is only available when SSL is used with client authentication is used. |
| javax.net.ssl.session | javax.net.ssl.SSLSession | An SSL session object, if the request was made using SSL. |
The package (and hence attribute) names beginning with java.*, and javax.* are reserved for use by Javasoft. Similarly, com.sun.* is reserved for use by Sun Microsystems.
getAttribute in interface javax.servlet.ServletRequestname - the name of the attribute whose value is required
public java.io.BufferedReader getReader()
throws java.io.IOException
getReader in interface javax.servlet.ServletRequestjava.io.UnsupportedEncodingException - if the character set encoding
is unsupported, so the text can't be correctly decoded.
java.lang.IllegalStateException - if getInputStream has been
called on this same request.
java.io.IOException - on other I/O related errors.getInputStream()public boolean isRequestedSessionIdFromURL()
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequestpublic java.lang.String getCharacterEncoding()
getCharacterEncoding in interface javax.servlet.ServletRequestpublic java.lang.String getContextPath()
getContextPath in interface javax.servlet.http.HttpServletRequestpublic java.util.Enumeration getAttributeNames()
getAttributeNames in interface javax.servlet.ServletRequestpublic java.util.Enumeration getHeaders(java.lang.String name)
getHeaders in interface javax.servlet.http.HttpServletRequestpublic java.util.Locale getLocale()
getLocale in interface javax.servlet.ServletRequestpublic java.util.Enumeration getLocales()
getLocales in interface javax.servlet.ServletRequestpublic javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
getRequestDispatcher in interface javax.servlet.ServletRequestpublic java.lang.StringBuffer getRequestURL()
getRequestURL in interface javax.servlet.http.HttpServletRequestpublic boolean isSecure()
isSecure in interface javax.servlet.ServletRequestpublic boolean isUserInRole(java.lang.String role)
isUserInRole in interface javax.servlet.http.HttpServletRequestpublic java.security.Principal getUserPrincipal()
getUserPrincipal in interface javax.servlet.http.HttpServletRequestpublic java.util.Map getParameterMap()
getParameterMap in interface javax.servlet.ServletRequest
public void setAttribute(java.lang.String name,
java.lang.Object value)
setAttribute in interface javax.servlet.ServletRequestpublic void removeAttribute(java.lang.String name)
removeAttribute in interface javax.servlet.ServletRequest
public void setCharacterEncoding(java.lang.String encoding)
throws java.io.UnsupportedEncodingException
setCharacterEncoding in interface javax.servlet.ServletRequestjava.io.UnsupportedEncodingExceptionpublic byte[] getRawData()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||