一般都会大于100M
不知道大家是如何干的 谢谢咯
------解决方案--------------------
package com.upload;
import com.jspsmart.upload.SmartUpload;
/*****
*
*author:East(张栋芳)
*date: 2008-7-19
*note: 上传文件和下载文件
*/
public class Upload {
/***
*
*上传文件平
*/
public void upLoad(){
// 新建一个SmartUpload对象
SmartUpload supload = new SmartUpload();
// 上传初始化
supload.initialize(pageContext);
// 限制每个上传文件的最大长度
supload.setMaxFileSize(10000);
// 限制总上传数据的长度。
supload.setTotalMaxFileSize(20000);
// 设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
supload.setAllowedFilesList("doc,txt");
// 设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat,
//jsp,htm,html扩展名的文件和没有扩展名的文件。
supload.setDeniedFilesList("exe,bat,jsp,html,htm");
// 上传文件
supload.upload();
// 将上传文件全部保存到指定目录
int count = supload.save("/upload");
com.jspsmart.upload.SmartFile file = supload.getFiles().getFile(0);
//文件名
String fileName = file.getFieldName();
}
/***
*
*下载文件
*/
public void downLoad(){
SmartUpload su = new SmartUpload();
su.initialize(pageContext);
// 设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
//doc时,浏览器将自动用word打开它。扩展名为pdf时,
//浏览器将用acrobat打开
su.setContentDisposition(null);
su.downloadFile("/upload/test.doc");
}
}
------解决方案--------------------
我写过一个上传,用于上传管理员向远程服器上传数据
- Java code
package com.niit.servlet;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.niit.bookshop.bean.Books;
import com.niit.bookshop.dao.BooksDAO;
public class UploadServlet extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Books book = new Books();
DiskFileItemFactory factory = new DiskFileItemFactory();
File path = new File(this.getServletContext().getRealPath("images\\"));