一个奇怪问题,环境不同,程序一样,一个可以显示图片,一个不可以

jinangchao 2015-04-21 11:59:10
程序应该是没问题的,因为在本地可以显示图片。本地tomcat的upload目录也是有保存图片。
但是架设到服务器,tomcat的upload目录保存了图片,但是就是读不出来,debug过,程序获取到的图片文件也是正确的。
有什么安全或者环境因素吗?

private void sendFileByTomcat(UploadFile uf, HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
File file = calculateRealPath(uf, false);
if(!file.exists() || !file.isFile()){
return;
}
String encoding = response.getCharacterEncoding();
request.setAttribute("org.apache.tomcat.sendfile.filename", file.getAbsolutePath());
request.setAttribute("org.apache.tomcat.sendfile.start", 0L);
request.setAttribute("org.apache.tomcat.sendfile.end", file.length());
response.setHeader("Content-Disposition", "filename=\"" + toPathEncoding(encoding, uf.getFileName() + uf.getType().getSuffix()+"\""));
response.setContentLength((int) file.length());
response.setContentType(uf.getType().getContentType());
}
...全文
183 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
want1615 2015-05-22
  • 打赏
  • 举报
回复
怎么解决的????
jinangchao 2015-04-21
  • 打赏
  • 举报
回复
引用 2 楼 houa123 的回复:
权限问题是不是。
应该不是权限问题,我也google过,国外朋友也遇到过这样的问题,解释说是服务器设置的文件content lenth和用户实际获取的不一致。。。
嗨_末班车 2015-04-21
  • 打赏
  • 举报
回复
权限问题是不是。
jinangchao 2015-04-21
  • 打赏
  • 举报
回复
不能显示图片的环境,访问会出现net::ERR_CONTENT_LENGTH_MISMATCH的错误

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧