摘要:本篇WEBAPP教程将为大家讲解WEBAPP编程的知识,看完这篇文章会让你对WEBAPP编程的知识有更加清晰的理解和运用。
本篇WEBAPP教程将为大家讲解WEBAPP编程的知识,看完这篇文章会让你对WEBAPP编程的知识有更加清晰的理解和运用。
@RequestMapping("/act/worldcup_schedule_time/imgdownload")
@ResponseBody
public String scheduleDownload(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
response.setCharacterEncoding("UTF-8");
String downLoadName = "worldcup.jpg";
InputStream input = null;
try {
request.setCharacterEncoding("UTF-8");
//获取文件的路径
// String url = session.getServletContext().getRealPath("/") + "resources\\images\\act\\worldcup_merge\\worldcup720.png";
String url = session.getServletContext().getRealPath("/") + "resources/images/act/worldcup_merge/worldcup720.png";
System.out.println(url);
File file = new File(url);
input = FileUtils.openInputStream(file);
byte[] data = IOUtils.toByteArray(input);
//System.out.println("文件名:"+downLoadName);
response.reset();
//设置响应的报头信息(中文问题解决办法)
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode(downLoadName, "UTF-8"));
response.addHeader("Content-Length", "" + data.length);
response.setContentType("image/png; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
} catch (Exception e) {
logger.error("下载图片出错");
if (input != null) {
IOUtils.closeQuietly(input);
}
}
return null;
}
以上,关于WEBAPP的全部内容讲解完毕啦,欢迎大家继续关注!更多关于WEBAPP的干货请关注职坐标WEBAPP频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号