急 !关于jsp上传文件的问题??
上传文件超过10k, 结果Demo.out用ultraEdit打开 ,前面都是对的 , 找不到结束标志 ,后面出现乱码。而文件很小与5k,就没有问题。
我的信箱:carrily@jlonline.com
文件一:
<html>
<head>
<title>文件上载</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="uploadfile.jsp" enctype="multipart/form-data">
<table align="center" cellspacing="1" cellpadding="1" >
<tr class="ftitle">
<td><input name="submit" type="submit" value="提交"></td>
</tr>
</table>
<input type="hidden" name="year" value="2004">
<input type="hidden" name="type" value="Theroy">
<input type="hidden" name="todo" value="upload">
<table width="75%" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td width="20%" class="TDTITLE" > 文件 :</td>
<td>
<div align="left">
<input type="file" name="fileTestResult">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
文件二 :<%@ page language="java" import="java.io.*"%>
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传文件</title>
</head>
<BODY BGCOLOR="white">
<%
java.io.File file = new java.io.File("ExcelResult/Demo.out");
java.io.FileOutputStream fout = new FileOutputStream(file);
DataInputStream is=new DataInputStream(request.getInputStream());
System.out.println("StreamLength="+request.getContentLength());
int i = 0 ;
try{
while(true){
fout.write(is.readByte());
i++;
}
}catch(Exception e){
System.out.println("error:"+e.getMessage()) ;
}
System.out.println("i="+i) ;
fout.close();
is.close();
%>
</BODY>
</HTML>