我在这个网站看见了几篇关于图片上传的bean,但是没有看见文本上传的bean 于是就写了个
上传文本的bean.此程序在tomcat4.1调试成功
package up;
import Java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class upjspBean {
int count=0;
int i=0;
String dataString=null;
String lastString=null;
public void doUpload(HttpServletRequest request) throws
IOException {
int indexof;
int n=0;
byte[]tmpdata=new byte[65536];
FileOutputStream fo=new FileOutputStream("a.txt");
BufferedOutputStream bo=new BufferedOutputStream(fo);
DataOutputStream file=new DataOutputStream(bo);
ServletInputStream si = request.getInputStream();
BufferedInputStream b i=new BufferedInputStream(si);
DataInputStream data=new DataInputStream(bi);
count=data.available();
try{while (true) {
tmpdata[count++] = data.readByte();
}}
catch(EOFException e) {data.close();}
dataString=new String(tmpdata,0,count);
indexof=dataString.indexOf("Content-Type:");
dataString=dataString.substring(indexof);
indexof=dataString.indexOf("
");
dataString=dataString.substring(indexof+4);
indexof=dataString.indexOf("-----------------------------7d3");
dataString=dataString.substring(0,indexof-2);
tmpdata=dataString.getBytes();
i=tmpdata.length;
file.write(tmpdata,0,i);
file.close();
}
public int getCount() {
return(i);
}
}