tomcat部署项目,图片访问不了,出现net::ERR_CONTENT_LENGTH_MISMATCH

jinangchao 2015-04-21 02:01:49
Header已经设置了ContentLength
但是访问图片还是会出现net::ERR_CONTENT_LENGTH_MISMATCH,导致图片显示不了
图片显示代码

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());
}
...全文
7980 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Canrz 2015-06-18
  • 打赏
  • 举报
回复
今天也碰到了这个问题,参照这篇的方案http://blog.csdn.net/defonds/article/details/46042809 直接root用户启动nginx
want1615 2015-05-22
  • 打赏
  • 举报
回复
后来怎么解决的
jinangchao 2015-04-21
  • 打赏
  • 举报
回复
引用 1 楼 u013762572 的回复:
在web.xml中配置一下你的中文问题:
<jsp-config>  
         <jsp-property-group>  
             <description>  
                 Special property group for JSP Configuration JSP example.  
             </description>  
             <display-name>JSPConfiguration</display-name>  
             <url-pattern>*.html</url-pattern>  
             <el-ignored>true</el-ignored>  
             <page-encoding>UTF-8</page-encoding>  
             <scripting-invalid>false</scripting-invalid>  
             <include-prelude></include-prelude>  
             <include-coda></include-coda>  
         </jsp-property-group>  
     </jsp-config>
配置完连页面都不显示了
jinangchao 2015-04-21
  • 打赏
  • 举报
回复
先mark,回家再尝试,因为这边环境是没问题的,家里的环境显示不了图片
microhex 2015-04-21
  • 打赏
  • 举报
回复
在web.xml中配置一下你的中文问题:
<jsp-config>  
         <jsp-property-group>  
             <description>  
                 Special property group for JSP Configuration JSP example.  
             </description>  
             <display-name>JSPConfiguration</display-name>  
             <url-pattern>*.html</url-pattern>  
             <el-ignored>true</el-ignored>  
             <page-encoding>UTF-8</page-encoding>  
             <scripting-invalid>false</scripting-invalid>  
             <include-prelude></include-prelude>  
             <include-coda></include-coda>  
         </jsp-property-group>  
     </jsp-config>

81,122

社区成员

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

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