文件或目录损坏且无法读取-qq游戏大厅2012

jsp格式怎么打开
2023年3月30日发(作者:金山毒霸下载)

<%@pagelanguage="java"contentType="application/x-

msdownload"pageEncoding="UTF-8"%>

<%@page

import=",oder,St

ream,ption,putStream"%>

<%

Stringfilename=

ameter("file")!=null?ameter("

file"):"";

if("".equals(filename)){//获取文件名,若为空则返回下载列表

uestDispatcher("").forw

ard(request,response);

return;

}

//获取服务器地址(效验文件是否存在时需要完整路径)

StringsCurrentPath=

vletContext().getRealPath

(vletPath());

intiPos=dexOf(tor);

sCurrentPath=ing(0,iPos);

iPos=dexOf(tor);

sCurrentPath=ing(0,iPos+1);

//关于文件下载时采用文件流输出的方式处理:

//加上(),并且所有的%>后面不要换行,包括最后

一个;

Stringfiledownload=sCurrentPath+"down"+

filename;

//n("filedownload="+filedownload);

Fileoldfile=newFile(filedownload);

if(()){//文件存在时

();//可以加也可以不加

tentType("application/x-

download");

Stringfiledisplay=filename;

filedisplay=(filedisplay,"UTF-

8");

der("Content-

Disposition","attachment;filename="+filedisplay);

//第一种写法

try{

RequestDispatcherdis=

uestDispatcher("/down/"+filename);

if(dis!=null){

d(request,response);

}

uffer();

}catch(Exceptione){

tackTrace();

}

finally{

}

//第二种写法(下载时不能获取文件大小)

//OutputStreamoutp=null;

//FileInputStreamin=null;

//try{

//outp=putStream();

//in=newFileInputStream(filedownload);

//

//byte[]b=newbyte[1024];

//inti=0;

//

//while((i=(b))>0){

//(b,0,i);

//}

//();

//}catch(Exceptione){

//n("Error!");

//sage();

////tackTrace();

//}

//finally{

//if(in!=null){

//();

//in=null;

//}

//if(outp!=null){

//();

//outp=null;

//}

//}

}else{

%>

<%

}

%>

更多推荐

jsp格式怎么打开