|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.opus5.servlet.MultipartRequest
A class for handling multipart form uploads. This version is for JSDK 2.2. de.opus5.serlvet.* handles multipart requests , which means you can use this library for file uploads. The MultipartRequest implements javax.servlet.htt.HttpServletRequest, so you can use the HttpServletRequest-API for multipart requests. There are some extensions for access to the uploaded files. The MultipartRequest class can store small uploads in main memory, if you want it to (see constructors for details). Access to the uploaded files is provided via the UploadedFile class, no mather if the files are temporary stored in main memory or disk. Access to the file data is provided via java streams, so you can easily write the file data wherever you like (ie directly to a database). A ready to use precompiled version is included in this archive. Note that this is free software and under the LGPL-license (see LICENCE file). Mail bugs, improovments, comments to mailto:frederik.dahlke@web.de
Example:
MulipartRequest req; .. try { req = new MultipartRequest(servletRequest,maxMemoryStoredRequestSize, tmpdir,fileprefix); } catch (Exception e) { ... } .... filename = req.getUploadedFile("Document").getName(); is = req.getInputStreamForFile("Document"); while (is.read()...) { ... } login = req.getParameter("Login"); ... UploadedFile adressFile = mReq.getUploadedFile(Global.MPADRESSF_KEY); UploadedFile docFile = mReq.getUploadedFile(Global.MPDOCFILE_KEY); myObject.setAdressFile(adressFile); .... ....
Inner Class Summary | |
class |
MultipartRequest.BucketHash
Simple class for storing parameters |
Constructor Summary | |
MultipartRequest(javax.servlet.http.HttpServletRequest sR,
int maxMemStoredReqSiz,
int maxReqSiz,
java.lang.String tmpDir,
java.lang.String uniquePrefix)
Create a MultipartRequest, temporary files will be deleted. |
|
MultipartRequest(javax.servlet.http.HttpServletRequest sR,
int maxMemStoredReqSiz,
java.lang.String tmpDir,
java.lang.String uniquePrefix)
Create a MultipartRequest, temporary files will be deleted, the maximum request size is set to 1MB. |
|
MultipartRequest(javax.servlet.http.HttpServletRequest sR,
int maxReqSiz,
java.lang.String tmpDir,
java.lang.String uniquePrefix,
boolean keep)
Create a MultipartRequest, files will be saved to disk allways. |
|
MultipartRequest(javax.servlet.http.HttpServletRequest sR,
java.lang.String tmpDir,
java.lang.String uniquePrefix)
Create a MultipartRequest using the HttpServletRequest object, temporary files will be deleted. |
Method Summary | |
java.lang.Object |
getAttribute(java.lang.String name)
Calls the corresponding method in ServletRequest-object. |
java.util.Enumeration |
getAttributeNames()
Calls the corresponding method in ServletRequest-object. |
java.lang.String |
getAuthType()
Returns the authentication scheme of the request, or null if none. |
java.lang.String |
getCharacterEncoding()
Calls the corresponding method in ServletRequest-object. |
int |
getContentLength()
Returns the size of the request entity data, or -1 if not known. |
java.lang.String |
getContentType()
|
java.lang.String |
getContextPath()
Returns the portion of the request URI that indicates the context of the request. |
javax.servlet.http.Cookie[] |
getCookies()
Gets the array of cookies found in this request. |
long |
getDateHeader(java.lang.String name)
Returns the value of a date header field, or -1 if not found. |
java.io.File |
getFile(java.lang.String fieldname)
returns a java.io.File object if the file was saved on disk, null otherwise. |
java.lang.String |
getHeader(java.lang.String name)
Returns the value of a header field, or null if not known. |
java.util.Enumeration |
getHeaderNames()
Returns an enumeration of strings representing the header names for this request. |
java.util.Enumeration |
getHeaders(java.lang.String name)
Returns all the values of the specified request header as an Enumeration of String objects. |
javax.servlet.ServletInputStream |
getInputStream()
Calls the corresponding method in ServletRequest-object. |
java.io.InputStream |
getInputStreamForFile(java.lang.String fieldname)
return an InputStream for reading an uploaded file. |
int |
getIntHeader(java.lang.String name)
Returns the value of an integer header field, or -1 if not found. |
java.util.Locale |
getLocale()
Calls the corresponding method in ServletRequest-object. |
java.util.Enumeration |
getLocales()
Calls the corresponding method in ServletRequest-object. |
java.lang.String |
getMethod()
Returns the method with which the request was made. |
java.lang.String |
getParameter(java.lang.String name)
return the value of parameter with specified name |
java.util.Enumeration |
getParameterNames()
return the names of all parameters as Enumeration |
java.lang.String[] |
getParameterValues(java.lang.String name)
return the value of the specified parameter as an array of strings. |
java.lang.String |
getPathInfo()
|
java.lang.String |
getPathTranslated()
Returns extra path information translated 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>.<minor
version> . |
java.lang.String |
getQueryString()
Returns the query string part of the presentation URI, or null if none. |
java.io.BufferedReader |
getReader()
Calls the corresponding method in ServletRequest-object. |
java.lang.String |
getRealPath(java.lang.String path)
Calls the corresponding method in ServletRequest-object. |
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()
Returns the name of the user making this request, or null if not known. |
javax.servlet.RequestDispatcher |
getRequestDispatcher(java.lang.String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. |
java.lang.String |
getRequestedSessionId()
|
java.lang.String |
getRequestURI()
Returns the request URI. |
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()
|
javax.servlet.http.HttpSession |
getSession()
|
javax.servlet.http.HttpSession |
getSession(boolean create)
|
UploadedFile |
getUploadedFile(java.lang.String fieldname)
Get the UploadedFile object for the uploaded file with given name. |
java.util.Enumeration |
getUploadedFiles()
Get an enumeration of the UploadedFile objects. |
java.security.Principal |
getUserPrincipal()
|
boolean |
isRequestedSessionIdFromCookie()
|
boolean |
isRequestedSessionIdFromUrl()
|
boolean |
isRequestedSessionIdFromURL()
|
boolean |
isRequestedSessionIdValid()
|
boolean |
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. |
boolean |
isUserInRole(java.lang.String role)
|
void |
removeAttribute(java.lang.String name)
Removes an attribute from this request. |
void |
setAttribute(java.lang.String name,
java.lang.Object o)
Stores an attribute in this request. |
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 sR, int maxMemStoredReqSiz, int maxReqSiz, java.lang.String tmpDir, java.lang.String uniquePrefix) throws java.lang.IllegalArgumentException, java.io.IOException
sR
- the HttpServletRequestmaxMemStoredReqSiz
- If the request size in bytes exceeds
this value, the uploaded files will be stored on disk.maxReqSiz
- Maximum size of request.tmpDir
- Directory where temporary files are saved.uniquePrefix
- Prefix added to the filenames to prevent
overwriting of files with the same name.public MultipartRequest(javax.servlet.http.HttpServletRequest sR, int maxMemStoredReqSiz, java.lang.String tmpDir, java.lang.String uniquePrefix) throws java.lang.IllegalArgumentException, java.io.IOException
sR
- the HttpServletRequestmaxMemStoredReqSiz
- If the request size in bytes exceeds
this value, the uploaded files will be stored on disk.tmpDir
- Directory where temporary files are saved.uniquePrefix
- Prefix added to the filenames to prevent
overwriting of files with the same name.public MultipartRequest(javax.servlet.http.HttpServletRequest sR, int maxReqSiz, java.lang.String tmpDir, java.lang.String uniquePrefix, boolean keep) throws java.lang.IllegalArgumentException, java.io.IOException
sR
- the HttpServletRequestmaxReqSiz
- Maximum size of request.tmpDir
- Directory where temporary files are saved.uniquePrefix
- Prefix added to the filenames to prevent
overwriting of files with the same name.keep
- If set, the uploaded files will not be deleted.public MultipartRequest(javax.servlet.http.HttpServletRequest sR, java.lang.String tmpDir, java.lang.String uniquePrefix) throws java.lang.IllegalArgumentException, java.io.IOException
sR
- the HttpServletRequesttmpDir
- Directory where temporary files are saved.uniquePrefix
- Prefix added to the filenames to prevent
overwriting of files with the same name.Method Detail |
public java.io.File getFile(java.lang.String fieldname)
fieldname
- the form parameter field namepublic java.io.InputStream getInputStreamForFile(java.lang.String fieldname) throws java.io.IOException
filename
- the form parameter field namepublic java.util.Enumeration getParameterNames()
public java.lang.String getParameter(java.lang.String name)
name
- the parameter namepublic java.lang.String[] getParameterValues(java.lang.String name)
public UploadedFile getUploadedFile(java.lang.String fieldname)
fieldname
- the form parameter field namepublic java.util.Enumeration getUploadedFiles()
public int getContentLength()
public java.lang.String getContentType()
public java.lang.String getProtocol()
<protocol>/<major version>.<minor
version>
. Same as the CGI variable SERVER_PROTOCOL.public java.lang.String getScheme()
public java.lang.String getServerName()
public boolean isSecure()
public void removeAttribute(java.lang.String name)
public void setAttribute(java.lang.String name, java.lang.Object o)
public int getServerPort()
public java.lang.String getRemoteAddr()
public java.lang.String getRemoteHost()
public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
public java.lang.String getMethod()
public java.lang.String getRequestURI()
public java.lang.String getPathTranslated()
public java.lang.String getQueryString()
public java.lang.String getRemoteUser()
public java.lang.String getAuthType()
public java.lang.String getContextPath()
public javax.servlet.http.Cookie[] getCookies()
public java.lang.String getHeader(java.lang.String name)
name
- the case-insensitive header field namepublic int getIntHeader(java.lang.String name)
name
- the case-insensitive header field namepublic long getDateHeader(java.lang.String name)
name
- the case-insensitive header field namepublic java.util.Enumeration getHeaderNames()
public java.util.Enumeration getHeaders(java.lang.String name)
public java.lang.Object getAttribute(java.lang.String name)
public java.util.Enumeration getAttributeNames()
public java.lang.String getRealPath(java.lang.String path)
public javax.servlet.ServletInputStream getInputStream() throws java.io.IOException
public java.util.Locale getLocale()
public java.util.Enumeration getLocales()
public java.io.BufferedReader getReader() throws java.io.IOException
public java.lang.String getCharacterEncoding()
public java.lang.String getRequestedSessionId()
HttpPresentationRequest#getRequestedSessionId
public java.lang.String getPathInfo()
HttpPresentationRequest#getPathInfo
public boolean isRequestedSessionIdFromCookie()
HttpPresentationRequest#isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromUrl()
HttpPresentationRequest#isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromURL()
HttpPresentationRequest#isRequestedSessionIdFromURL
public javax.servlet.http.HttpSession getSession()
HttpPresentationRequest#getSession
public javax.servlet.http.HttpSession getSession(boolean create)
HttpPresentationRequest#getSession
public java.security.Principal getUserPrincipal()
HttpPresentationRequest#getUserPrinicpal
public boolean isRequestedSessionIdValid()
HttpPresentationRequest#isRequestedSessionIdValid
public boolean isUserInRole(java.lang.String role)
HttpPresentationRequest#isUserInRole
public java.lang.String getServletPath()
HttpPresentationRequest#getServletPath
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |