// Copyright (C) 1998-2001 by Jason Hunter <jhunter_AT_acm_DOT_org>.
// All rights reserved. Use of this class is limited.
// Please see the LICENSE for more information.
package share.tools.servlet;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import share.tools.servlet.multipart.FilePart;
import share.tools.servlet.multipart.FileRenamePolicy;
import share.tools.servlet.multipart.MultipartParser;
import share.tools.servlet.multipart.ParamPart;
import share.tools.servlet.multipart.Part;
/**
* A utility class to handle <code>multipart/form-data</code> requests,
* the kind of requests that support file uploads. This class emulates the
* interface of <code>HttpServletRequest</code>, 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
* <code>MultipartParser</code> instead.
* <p>
* 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 <b>can</b> now with the latest release handle internationalized content
* (such as non Latin-1 filenames).
* <p>
* 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.
* <p>
* See the included upload.war for an example of how to use this class.
* <p>
* The full file upload specification is contained in experimental RFC 1867,
* available at <a href="http://www.ietf.org/rfc/rfc1867.txt">
* http://www.ietf.org/rfc/rfc1867.txt</a>.
*
* @see MultipartParser
*
* @author Jason Hunter
* @author Geoff Soutter
* @version 1.11, 2002/11/01, combine query string params in param list<br>
* @version 1.10, 2002/05/27, added access to the original file names<br>
* @version 1.9, 2002/04/30, added support for file renaming, thanks to
* Changshin Lee<br>
* @version 1.8, 2002/04/30, added support for internationalization, thanks to
* Changshin Lee<br>
* @version 1.7, 2001/02/07, made fields protected to increase user flexibility<br>
* @version 1.6, 2000/07/21, redid internals to use MultipartParser,
* thanks to Geoff Soutter<br>
* @version 1.5, 2000/02/04, added auto MacBinary decoding for IE on Mac<br>
* @version 1.4, 2000/01/05, added getParameterValues(),
* WebSphere 2.x getContentType() workaround,
* stopped writing empty "unknown" file<br>
* @version 1.3, 1999/12/28, IE4 on Win98 lastIndexOf("boundary=")
* workaround<br>
* @version 1.2, 1999/12/20, IE4 on Mac readNextPart() workaround<br>
* @version 1.1, 1999/01/15, JSDK readLine() bug workaround<br>
* @version 1.0, 1998/09/18<br>
*/
public class MultipartRequest {
private static final int DEFAULT_MAX_POST_SIZE = 1024 * 1024; // 1 Meg
protected Hashtable parameters = new Hashtable(); // name - Vector of values
protected Hashtable files = new Hashtable(); // name - UploadedFile
/**
* 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. If the content is too large, an
* IOException is thrown. This constructor actually parses the
* <tt>multipart/form-data</tt> and throws an IOException if there's any
* problem reading or parsing the request.
*
* @param request the servlet request.
* @param saveDirectory the directory in which to save any uploaded files.
* @exception IOException if the uploaded content is larger than 1 Megabyte
* or there's a problem reading or parsing the request.
*/
public MultipartRequest(HttpServletRequest request,
String saveDirectory) throws IOException {
this(request, saveDirectory, DEFAULT_MAX_POST_SIZE);
}
/**
* 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. If the content is too large, an
* IOException is thrown. This constructor actually parses the
* <tt>multipart/form-data</tt> and throws an IOException if there's any
* problem reading or parsing the request.
*
* @param request the servlet request.
* @param saveDirectory the directory in which to save any uploaded files.
* @param maxPostSize the maximum size of the POST content.
* @exception IOException if the uploaded content is larger than
* <tt>maxPostSize</tt> or there's a problem reading or parsing the request.
*/
public MultipartRequest(HttpServletRequest request,
String saveDirectory,
int maxPostSize) throws IOException {
this(request, saveDirectory, maxPostSize, null, null);
}
/**
* 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. If the content is too large, an
* IOException is thrown. This constructor actually parses the
* <tt>multipart/form-data</tt> and throws an IOException if there's any
* problem reading or parsing the request.
*
* @param request the servlet request.
* @param saveDirectory the directory in which to save any uploaded files.
* @param encoding the encoding of the response, such as ISO-8859-1
* @exception IOException if the uploaded content is larger than
* 1 Megabyte or there's a problem reading or parsing the request.
*/
public MultipartRequest(HttpServletRequest request,
String saveDirectory,
String encoding) throws IOException {
this(request, saveDirectory, DEFAULT_MAX_POST_SIZE, encoding, null);
}
/**
* 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. If the content is too large, an
* IOException is thrown. This constructor actually parses the
* <tt>multipart/form-data</tt> and throws an IOException if there's any
* problem reading or parsing the request.
*
* @param request the servlet request.
* @param saveDirectory the directory in which to save any uploaded files.
* @param maxPostSize the maximum size of the POST content.
* @param encoding the encoding of the response, such as ISO-8859-1
* @exception IOException if the uploaded content is larger than
* <tt>maxPostSize</tt> or there's a problem reading or parsing the request.
*/
public MultipartRequest(HttpServletRequest request,
String saveDirectory,
int maxPostSize,
FileRenamePolicy policy) throws IOException {
this(request, saveDirectory, maxPostSize, null, 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. If the content is too large, an
* IOException is thrown. This constructor actually parses the
* <tt>multipart/form-data</tt> and throws an IOException if there's any
* problem reading or parsing the request.
*
* @param request the servlet request.
* @param saveDirectory the directory in which to save any uploaded files.
* @param maxPostSize the maximum size of the POST content.
* @param encoding the encoding of the response, such as ISO-8859-1
* @exception IOExcep
没有合适的资源?快使用搜索试试~ 我知道了~
多文件上传功能源码MultipartRequest.
共45个文件
java:45个
5星 · 超过95%的资源 需积分: 49 59 下载量 30 浏览量
2008-11-08
14:10:51
上传
评论
收藏 81KB RAR 举报
温馨提示
多文件上传功能源码,实现多个文件上传,该源码已经修改过,保存中文文件时,会先encode。。。
资源推荐
资源详情
资源评论
收起资源包目录
multipart.rar (45个子文件)
servlet
ParameterNotFoundException.java 803B
ParameterParser.java 13KB
MultipartRequest.java 19KB
MailMessage.java 11KB
DaemonHttpServlet.java 4KB
CookieParser.java 9KB
MultipartResponse.java 4KB
ServletUtils.java 8KB
CookieNotFoundException.java 784B
RemoteDaemonHttpServlet.java 4KB
Base64Encoder.java 6KB
HttpsMessage.java 6KB
RemoteHttpServlet.java 5KB
LocaleNegotiator.java 8KB
multipart
MacBinaryDecoderOutputStream.java 2KB
MultipartParser.java 18KB
ParamPart.java 3KB
FileRenamePolicy.java 724B
BufferedServletInputStream.java 6KB
FilePart.java 7KB
PartInputStream.java 8KB
LimitedServletInputStream.java 4KB
DefaultFileRenamePolicy.java 2KB
Part.java 1KB
MultipartFilter.java 2KB
VersionDetector.java 3KB
ReloadAction.java 1KB
CacheHttpServlet.java 12KB
LocaleToCharsetMap.java 2KB
HttpMessage.java 8KB
Upload.java 4KB
UploadFile.java 462B
Base64Decoder.java 6KB
CharacterEncodingFilter.java 891B
MultipartWrapper.java 2KB
multipart
MacBinaryDecoderOutputStream.java 2KB
MultipartParser.java 18KB
ParamPart.java 3KB
FileRenamePolicy.java 724B
BufferedServletInputStream.java 6KB
FilePart.java 7KB
PartInputStream.java 8KB
LimitedServletInputStream.java 4KB
DefaultFileRenamePolicy.java 2KB
Part.java 1KB
共 45 条
- 1
dugu666
- 粉丝: 24
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页