日期:2014-05-17  浏览次数:20732 次

servlet上传文件问题(ISO无法上传)
如题,也是网上找来的代码,自己调了一下,基本没什么问题,但现在遇到一个比较大的麻烦是基本EXE文件都可以上传,测试了900M的都可以,但是ISO文件上传了一个800M,一个3.5G的,通通失败,800M的那个好像有一部分没有上传,而3.5G的在TOMCAT目录下容量是0K!,目前还没从算法上找出问题(虽然是人家的算法,但我已经是理解了),所以请高手来看看。
JSP部分

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<form name="form1" method="post" action="up" enctype="multipart/form-data">
<input type="file" name="select" size=50>
<input type="submit" value="提交">
</form>
</body>
</html>


servlet部分


package sjw.pratice;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.FileItemFactory;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;

/**
 * Servlet implementation class up
 */
@WebServlet("/up")
public class up extends HttpServlet {
private static final long serialVersionUID = 1L;
    public up() {
        super();
    }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExceptionIOException {
// TODO Auto-generated method stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletInputStream in=request.getInputStream();
int len=request.getContentLength();
response.setContentType("text/html;utf-8");
PrintWriter out=response.getWriter();
byte[] b=new byte[128];
int i=0;
i=in.readLine(b, 0, 128);
len-=i;
i=in.readLine(b, 0, 128);
len-=i;
String s=new String(b,0,i);
String filename=s.substring(s.lastIndexOf("=")+2,s.lastIndexOf("\""));
if(filename.equals("")==false)
{
String savename=filename.substring(filename.lastIndexOf("\\")+1);
i=in.readLine(b, 0, 128);
len-=i;
i=in.readLine(b, 0, 128);
len-=i;
FileOutputStream fos=new FileOutputStream(request.getRealPath("")+"/"+s