Java 无法为Chrome中的图像加载资源

Java 无法为Chrome中的图像加载资源,java,php,image,tomcat,Java,Php,Image,Tomcat,我在chrome上遇到了一个奇怪的问题。我从服务器上得到了一个在Firefox中运行良好的图像,但在chrome中,图像加载一次,然后显示为损坏的图像 在Chrome控制台中,我收到以下消息: Resource interpreted as Image but transferred with MIME type text/html: "http://46.137.249.133:8080/Smart/Request/query.htm?ReqType=SessionUnawareAttachm

我在chrome上遇到了一个奇怪的问题。我从服务器上得到了一个在Firefox中运行良好的图像,但在chrome中,图像加载一次,然后显示为损坏的图像

在Chrome控制台中,我收到以下消息:

Resource interpreted as Image but transferred with MIME type text/html: "http://46.137.249.133:8080/Smart/Request/query.htm?ReqType=SessionUnawareAttachmentDownloadReqType&Thumbnail=Yes&AttachmentRowID=344929138455741006"
GET http://46.137.249.133:8080/Smart/Request/query.htm?ReqType=SessionUnawareAttachmentDownloadReqType&Thumbnail=Yes&AttachmentRowID=344929138455741006  
我还检查了mime类型,但没有检查它的image/jpeg。下面是
getimagesize()的输出


在query.html中,在输出任何内容之前(理想情况下,在脚本的开头),添加:


它会告诉浏览器返回的内容是JPEG图像。

这是
curl--verbose
的输出,您可以看到web服务器(在端口8080上)正在以
text/html
的形式宣传该文件

< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
[...]
< Content-Disposition: attachment; filename="Hall2.JPG"
< Content-Type: text/html;charset=ISO-8859-1
这与Java Servlet页面非常相似:

HttpServletResponse res;
res.setContentType("image/jpeg");

getimagesize可以查看数据,而不是http头。您需要有一个正确的内容类型。我需要在服务器中添加此内容?因为这些图像来自java而不是php,所以我给你一个php的答案。对不起,有没有什么解决方案可以让我在php文件中编码我不能添加
头('Content-Type:image/jpeg')因为服务器是用JAVA编写的,我可以在PHP文件中做些什么吗?这与用JAVA编写非常相似。我已将命令添加到我的响应中。
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
[...]
< Content-Disposition: attachment; filename="Hall2.JPG"
< Content-Type: text/html;charset=ISO-8859-1
header('Content-Type: image/jpeg');
HttpServletResponse res;
res.setContentType("image/jpeg");