日期:2014-05-18  浏览次数:20767 次

在jsp上传过程中上传进度条怎么真实体现出来
我做了一个上传的功能,在jsp上传过程中上传进度条怎么真实体现出来(包括如何取得客户端上传文件的大小)

------解决方案--------------------
你用哪种上传方式?是自己写的还是用开源的?
------解决方案--------------------
自己写的代码如下:
<%@ page contentType= "text/html;charset=gb2312 " %>
<%@ page import= "java.io.* " %>
<html>
<head> <title> 上传完成 </title> </head>
<body>
<%
String tempfilename = session.getId();
int n;
File f1 = new File( "E:/UpLoad_BOE ",tempfilename);//临时文件
try{
InputStream in = request.getInputStream();
//DataInputStream b_in = new DataInputStream(in);
BufferedInputStream b_in = new BufferedInputStream(in);
/*******************文件大小**************************/
//int allLength=b_in.available();
//session.setAttribute( "FileSize ",new Integer(allLength));
//System.out.println( "@@@@@@@@@@@@@@@@@@@@@@@上传的大小为: "+allLength);
//session.setAttribute( "InputStream ",in);
/*****************************************************/
FileOutputStream f_out = new FileOutputStream(f1);
BufferedOutputStream b_out = new BufferedOutputStream(f_out);
//DataOutputStream b_out=new DataOutputStream(f_out);
byte[] b = new byte[1000];
while((n=b_in.read(b))!=-1){
b_out.write(b,0,n);
}
b_out.flush();
b_out.close();
f_out.close();
b_in.close();
in.close();
out.print( "文件上传成功! <br> ");
}
catch(IOException e){
}

try{
RandomAccessFile rf = new RandomAccessFile(f1, "r ");
rf.readLine();
String fileName = rf.readLine();
byte[] b_fileName = fileName.getBytes( "ISO-8859-1 ");
fileName = new String(b_fileName);
int name_point = fileName.lastIndexOf( "\\ ");
fileName = fileName.substring(name_point+1,fileName.length()-1);


File f2 = new File( "E:/UpLoad_BOE ",fileName);
RandomAccessFile rf2 = new RandomAccessFile(f2, "rw ");
rf.seek(0);
for(int i=0;i <4;i++){
rf.readLine();
}
long startPoint = rf.getFilePointer();//取得文件内容的开始位置(从第4行结束位置起)

rf.seek(rf.length());//把指针定位到文件结束处
long mark = rf.getFilePointer();//取得文件结尾处偏移量
int j=0;
long endPoint = 0;
while(mark> =0 && j <=5){
mark--;
rf.seek(mark);
byte b_mark = rf.readByte();
if(b_mark== '\n '){
j++;
endPoint=rf.getFilePointer();//取得文件内容的结束位置(倒数第6行往上的内容)
}
}
long lenght = endPoint-startPoint+1;//文件的长度
int order = (int)(lenght/10000);
int left = (int)(lenght%10000);
byte[] c = new byte[10000];
rf.seek(startPoint);//定位指针到文件内容的开始位置
for(int i=0;i <order;i++){
rf.read(c);
rf2.write(c);
}
rf.read(c,0,left);
rf2.write(c,0,left);
rf.close();
rf2.close();
f1.delete();
session.setAttribute( "success ", "Y ");
out.print( "文件更新成功! ");
String str=response.encodeURL( "Child_center4.jsp ");
response.sendRedirect(str);
}
catch(IOException e1){
out.print( "文件更新失败! ");
}
%>
</body>
</html>
------解决方案--------------------
我也想要,帮你关注
------解决方案--------------------