自己做了一个上传的bean,出了点问题,各位帮忙看看!

04-12-22 ddydy
//部分代码

public class upload {

public HttpServletRequest request;

private byte[] b = new byte[4096];//字节流存放数组

private int FileCount=0;//

public void setRequest(HttpServletRequest Request)

{

this.request=Request;

}

public upload(){

}

//获取text框内容

public String getText(String FieldName) throws java.io.IOException

{

ServletInputStream sis ;

sis = request.getInputStream();

System.out.println(FieldName);

String ReturnValues="";

String SplitStr="";

int a = 0;

int k=0;

String s = "";

boolean isend=false;

System.out.println("-----start---------");

while ((a = sis.readLine(b, 0, b.length)) != -1&&!isend) {

//while start

s=new String(b,0,a);

System.out.println(s);

if(s.indexOf("Content-Disposition: form-data; name=\""+FieldName+"\"")!=-1)//获得指定字段名的value值

{//if start

System.out.println("ok");

a = sis.readLine(b,0,b.length);

s = new String(b,0,a);

while(true)

{//while start

a=sis.readLine(b,0,b.length);

s=new String(b,0,a);

if((b[0]==45)&&(b[1]==45)&&(b[2]==45)&&(b[3]==45)&&(b[4]==45))

{

isend = true;

break;

}

else

ReturnValues=ReturnValues+s;

}//while end

}//if end

}//while end

sis.close();

return ReturnValues;

}

====================

调用时:

out.println(ddy.getText("t1"));

out.println(ddy.getText("t2"));

在读t2得值的时候,数据流总是从读t1停止的地方开始,不知道怎么解决

猜你喜欢