博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
servlet提供下载图片服务
阅读量:7088 次
发布时间:2019-06-28

本文共 1151 字,大约阅读时间需要 3 分钟。

hot3.png

public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {    	response.setContentType("text;html;charset=utf-8");    	DataOutputStream output=new DataOutputStream(response.getOutputStream());    	String imagePath = "D://home.jpg";    	//http://localhost:8080/HelloWorldServlet/MyFirstServlet?username=xxxx&password=111    	  String username=request.getParameter("username");    	  String password=request.getParameter("password");    	  System.out.println("username="+username);    	  System.out.println("password="+password);    	  System.out.println("servlet test success....");    	  response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("home.jpg", "UTF-8"));       	  response.setHeader("Content-Type", "application/octet-stream");     	      	  FileInputStream fis = new FileInputStream(imagePath);          int size =fis.available(); //得到文件大小             byte data[]=new byte[size];             fis.read(data);  //读数据             fis.close();     	            output.write(data);          output.close();    }

转载于:https://my.oschina.net/u/589963/blog/404327

你可能感兴趣的文章
Go语言程序的命令行参数
查看>>
Microsoft CRM 2011 出现“无法更改域登录名" 错误
查看>>
关于Lua程序设计{读书笔记}
查看>>
EasyUI1.3.1+MVC4.0+EF5.0实战之一 开篇及布局控件介绍
查看>>
如何控制线程执行的顺序
查看>>
超级密码 hdu1226 bfs
查看>>
关于对接BRT 串口协议的一些工作
查看>>
springboot将项目源代码打包
查看>>
Python必会的单元测试框架 —— unittest
查看>>
CentOS 7配置MariaDB允许指定IP远程连接数据库
查看>>
计算机基础——指令与程序
查看>>
jeecg查询条件组装器使用or关键字
查看>>
用三段 140 字符以内的代码生成一张 1024×1024 的图片<转载>
查看>>
HTML CSS
查看>>
关于博客园主题的说明
查看>>
秦涛:深度学习的五个挑战和其解决方案
查看>>
13 个最佳 JavaScript 数据网格库
查看>>
python 之format字符串格式化
查看>>
struts2中s:iterator的使用(2个list嵌套循环)
查看>>
css3 放大缩小代码
查看>>