Search code examples
javatomcatjava-web-startjnlp

Tomcat is serving JNLP Files with the content type "text/html" instead of the JNLP content type


I've setup a Tomcat for a java web start application. Now I'm offering the .JNLP files as download on a static html page (The server is just for internal purposes). But when I click on a file instead of downloading it it opens up and shows the xml code in the browser.

With fiddler I found out that the file will be server with the content type text/htmlinstead of application/x-java-jnlp-file.

I've already configured the following stuff in my 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>

Why is Tomcat serving the file with the wrong Content-type?


Solution

  • I've found a solution for my case.

    I pasted the mime-mapping tags in my global web.xml of my tomcat. After restarting the server and clearing the browser cache it was working as expected.

    What I've learned: There's no need for an extra servlet to download JNLP files.