jsp中response实现图片下载
2014-02-25 22:19
776 查看
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String path = this.getServletContext().getRealPath("/download/中国.png");
String filename=path.substring(path.indexOf("\\")+1);
response.setHeader("content-disposition", "attachment;filename="+RUL(filename,“UTF-8”));
FileInputStream in=null;
ServletOutputStream out=null;
try{
in=new FileInputStream(path);
int len=0;
byte buffer[]=new byte[1024];
out=response.getOutputStream();
while((len=in.read(buffer))>0){
out.write(buffer,0,len);
}
}finally{
if(in!=null){
try{
in.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
throws ServletException, IOException {
String path = this.getServletContext().getRealPath("/download/中国.png");
String filename=path.substring(path.indexOf("\\")+1);
response.setHeader("content-disposition", "attachment;filename="+RUL(filename,“UTF-8”));
FileInputStream in=null;
ServletOutputStream out=null;
try{
in=new FileInputStream(path);
int len=0;
byte buffer[]=new byte[1024];
out=response.getOutputStream();
while((len=in.read(buffer))>0){
out.write(buffer,0,len);
}
}finally{
if(in!=null){
try{
in.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
相关文章推荐
- JSP响应的处理过程&JSP的三类语法
- JS基础的一些东西
- ExtJs4 MVC分析simple - examples源码分析
- prototype.js 1.4版开发者手册(强烈推荐)
- JS兼容性总结
- 安卓中遇到服务端json返回处理错误
- CreateJS奥运五环动画
- JSP----An internal error occurred during: "Requesting JavaScript AST from selection"
- 市委组织部项目--js调用后台方法(一)
- C#代码 json类
- Extjs 弹出窗口
- javascript call()方法和this对象的使用
- javascript变量
- js学习笔记 理解原型对象
- 原生js实现淘宝首页回到顶部效果
- ExtJS学习之HelloWorld
- js前台与后台数据交互-后台调前台(后台调用、注册客户端脚本)
- js前台与后台数据交互-前台调后台
- 如何在命令行中打印格式化的json和xml数据
- JS获取action里session.put("sendMeg", message) 设置的值