![](/img/trans.png)
[英]Tomcat serving wrong content type "text/html" for .svg resource
[英]Tomcat is serving JNLP Files with the content type “text/html” instead of the JNLP content type
我已经为 java web 启动应用程序设置了 Tomcat。 现在我在 static html 页面上提供.JNLP
文件下载(该服务器仅用于内部用途)。 但是当我点击一个文件而不是下载它时,它会打开并在浏览器中显示 xml 代码。
通过提琴手,我发现该文件将是内容类型为text/html
而不是application/x-java-jnlp-file
服务器。
我已经在我的 tomcat web.xml 中配置了以下内容:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<mime-mapping>
<extension>jnlp</extension>
<mime-type>application/x-java-jnlp-file</mime-type>
</mime-mapping>
为什么 Tomcat 提供的文件内容类型错误?
我已经为我的情况找到了解决方案。
我在我的 tomcat 的全局web.xml
中粘贴了mime-mapping
标签。 重新启动服务器并清除浏览器缓存后,它按预期工作。
我学到了什么:下载 JNLP 文件不需要额外的 servlet。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.