public class MultipartRequest extends Object
multipart/form-data requests,
the kind of requests that support file uploads. This class emulates the
interface of HttpServletRequest, making it familiar to use.
It uses a "push" model where any incoming files are read and saved directly
to disk in the constructor. If you wish to have more flexibility, e.g.
write the files to a database, use the "pull" model
MultipartParser instead.
This class can receive arbitrarily large files (up to an artificial limit you can set), and fairly efficiently too. It cannot handle nested data (multipart content within multipart content). It can now with the latest release handle internationalized content (such as non Latin-1 filenames).
To avoid collisions and have fine control over file placement, there's a constructor variety that takes a pluggable FileRenamePolicy implementation. A particular policy can choose to rename or change the location of the file before it's written.
See the included upload.war for an example of how to use this class.
The full file upload specification is contained in experimental RFC 1867, available at http://www.ietf.org/rfc/rfc1867.txt.
MultipartParser| 限定符和类型 | 字段和说明 |
|---|---|
protected com.oreilly.servlet.FileMap |
files |
protected Hashtable |
parameters |
| 构造器和说明 |
|---|
MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory)
Constructs a new MultipartRequest to handle the specified request,
saving any uploaded files to the given directory, and limiting the
upload size to 1 Megabyte.
|
MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize)
Constructs a new MultipartRequest to handle the specified request,
saving any uploaded files to the given directory, and limiting the
upload size to the specified length.
|
MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
FileRenamePolicy policy)
Constructs a new MultipartRequest to handle the specified request,
saving any uploaded files to the given directory, and limiting the
upload size to the specified length.
|
MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
String encoding)
Constructs a new MultipartRequest to handle the specified request,
saving any uploaded files to the given directory, and limiting the
upload size to the specified length.
|
MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
String encoding,
FileRenamePolicy policy) |
MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
String encoding)
Constructs a new MultipartRequest to handle the specified request,
saving any uploaded files to the given directory, and limiting the
upload size to the specified length.
|
MultipartRequest(javax.servlet.ServletRequest request,
String saveDirectory)
Constructor with an old signature, kept for backward compatibility.
|
MultipartRequest(javax.servlet.ServletRequest request,
String saveDirectory,
long maxPostSize)
Constructor with an old signature, kept for backward compatibility.
|
| 限定符和类型 | 方法和说明 |
|---|---|
String |
getContentType(String name)
Returns the content type of the specified file (as supplied by the
client browser), or null if the file was not included in the upload.
|
File |
getFile(String name)
Returns a File object for the specified file saved on the server's
filesystem, or null if the file was not included in the upload.
|
Enumeration |
getFileNames()
Returns the names of all the uploaded files as an Enumeration of
Strings.
|
Set<String> |
getFileNameSet()
jfinal 3.2 以及后续版本使用该方法来取出上传文件的文件名
避免构造 Enumeration 对象
|
String |
getFilesystemName(String name)
Returns the filesystem name of the specified file, or null if the
file was not included in the upload.
|
String |
getOriginalFileName(String name)
Returns the original filesystem name of the specified file (before any
renaming policy was applied), or null if the file was not included in
the upload.
|
String |
getParameter(String name)
Returns the value of the named parameter as a String, or null if
the parameter was not sent or was sent without a value.
|
Enumeration |
getParameterNames()
Returns the names of all the parameters as an Enumeration of
Strings.
|
String[] |
getParameterValues(String name)
Returns the values of the named parameter as a String array, or null if
the parameter was not sent.
|
void |
parse(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
String encoding,
FileRenamePolicy policy)
Constructs a new MultipartRequest to handle the specified request,
saving any uploaded files to the given directory, and limiting the
upload size to the specified length.
|
protected Hashtable parameters
protected com.oreilly.servlet.FileMap files
public MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory)
throws IOException
request - the servlet request.saveDirectory - the directory in which to save any uploaded files.IOException - if the uploaded content is larger than 1 Megabyte
or there's a problem reading or parsing the request.public MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize)
throws IOException
request - the servlet request.saveDirectory - the directory in which to save any uploaded files.maxPostSize - the maximum size of the POST content.IOException - if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.public MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
String encoding)
throws IOException
request - the servlet request.saveDirectory - the directory in which to save any uploaded files.encoding - the encoding of the response, such as ISO-8859-1IOException - if the uploaded content is larger than
1 Megabyte or there's a problem reading or parsing the request.public MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
FileRenamePolicy policy)
throws IOException
request - the servlet request.saveDirectory - the directory in which to save any uploaded files.maxPostSize - the maximum size of the POST content.policy - the rules for renaming in case of file name collisionsIOException - if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.public MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
String encoding)
throws IOException
request - the servlet request.saveDirectory - the directory in which to save any uploaded files.maxPostSize - the maximum size of the POST content.encoding - the encoding of the response, such as ISO-8859-1IOException - if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.public MultipartRequest(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
String encoding,
FileRenamePolicy policy)
throws IOException
IOExceptionpublic MultipartRequest(javax.servlet.ServletRequest request,
String saveDirectory)
throws IOException
IOExceptionpublic MultipartRequest(javax.servlet.ServletRequest request,
String saveDirectory,
long maxPostSize)
throws IOException
IOExceptionpublic void parse(javax.servlet.http.HttpServletRequest request,
String saveDirectory,
long maxPostSize,
String encoding,
FileRenamePolicy policy)
throws IOException
request - the servlet request.saveDirectory - the directory in which to save any uploaded files.maxPostSize - the maximum size of the POST content.encoding - the encoding of the response, such as ISO-8859-1policy - a pluggable file rename policyIOException - if the uploaded content is larger than
maxPostSize or there's a problem reading or parsing the request.public Enumeration getParameterNames()
public Enumeration getFileNames()
public Set<String> getFileNameSet()
public String getParameter(String name)
name - the parameter name.public String[] getParameterValues(String name)
name - the parameter name.public String getFilesystemName(String name)
name - the html page's file parameter name.public String getOriginalFileName(String name)
name - the html page's file parameter name.public String getContentType(String name)
name - the html page's file parameter name.Copyright © 2022. All rights reserved.