jsp页面点击按钮至控制类,以下只显示类文件:
@RequestMapping(params = "method=download")
public void download(HttpServletResponse response,String path,HttpServletRequest request) throws IOException{
response.setContentType(CONTENT_TYPE);
File file=new File(path);
String fileName=file.getName();
// response.setContentType("application/x-msdownload");
// response.setContentType("application/octet-stream");
response.setContentType("text/html;charset=utf-8");
// ((ServletRequest) response).setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition","attachment;filename="+new String(fileName.getBytes()));
String filePath=request.getRealPath("/")+File.separator+"file"+File.separator+fileName;
FileInputStream fis=new FileInputStream(filePath);
// FileInputStream fis=new FileInputStream(path);
// BufferedInputStream buff=new BufferedInputStream(fis);
OutputStream os=new BufferedOutputStream(response.getOutputStream());
// ServletOutputStream sout = response.getOutputStream();
// PrintWriter os = new PrintWriter(new BufferedWriter(response.getWriter()));
os.flush();
// JspWriter out = null;
// ServletContext pageConte
// out.clear();
// out = pageContext.pushBody();
// byte[] buffer=new byte[fis.available()];
// fis.read(buffer);
// fis.close();
// buff.read(buffer);
// buff.close();
// response.reset();
byte[] b=new byte[100];
int len=0;
while((len=fis.read(b))>0){
// response.reset();
os.write(b,0,len);
// os.write(len);
}
// os.write(buffer);
os.flush();
os.close();
// return response;
}