| |
我在这个网站看见了几篇关于图片上传的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); } }
|
|