当我尝试上传11.4 MB文本文件时出现此错误。
EXC E:java.io.IOException: Posted content length of 12000169 exceeds limit of 1048576
这是 upload.jsp
<html>
<body >
<form action="read.jsp" method="post" ENCTYPE="multipart/form-data" >
<head>
<link rel="stylesheet" type="text/css" href="./css/master.css" />
<link rel="stylesheet" type="text/css" href="./css/nav.css" />
</head>
<p>
<h1>UPLOAD</h1><br>
</p>
<p>
<h3> Please specify a file:</h3><br>
<input type="file" name="file" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>
</body>
</html>
这是 read.jsp
<html>
<head>
<title>display</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%@page import="java.io.*" %>
<%@page import="com.oreilly.servlet.MultipartRequest" %>
</head>
<body >
<link rel="stylesheet" type="text/css" href="./css/master.css" />
<link rel="stylesheet" type="text/css" href="./css/nav.css" />
<p>
<h1> read text file</h1><br>
</p>
<%
String path="/apps/text/";
String fileName="";
String PhoneModel = GetPhoneModel();
File a1=null;
try{
MultipartRequest multi=new MultipartRequest(request, path);
a1=multi.getFile("file");
} catch (Exception e){out.print("EXC E:"+e);}
try{
BufferedReader is = new BufferedReader(new FileReader(a1));
String fileData = "";
String crossSell="";
while((fileData = is.readLine()) != null)
{
out.println(fileData
}
}catch(Exception e){}
%>
<p>
<h1>Process Completed!</h1><br>
</p>
</body>
</html>
如何删除内容长度的最大限制,以便我可以上传大文件?
答案 0 :(得分:2)
MultipartRequest的默认最大大小为1048576.您可以在调用构造函数时更改此值。
MultipartRequest multi=new MultipartRequest(request, path, newSize);