Generating jnlp files from a jsp – http headers for IE
There are some advantages in generating a jnlp file for a webstart application from a .jsp. If you do this, you can dynamically generate the jnlp content (e.g. URLs, system properties, startup parameters) based upon the applications current deployment settings or environment.
However, as usual there are gotchas. IE often fails to recognise the webstart app, even if you set the content-type properly to application/x-java-jnlp-file.
To get it to go, you have to also use the http header Content-Disposition
Inserting the following into the jsp seems to solve this problem for us, and improve the chance that the browser does not cache the jnlp contents:
response.setContentType("application/x-java-jnlp-file");
response.setHeader("Cache-Control", "must-revalidate");
response.setHeader("Pragma", "no-cache");
long now = System.currentTimeMillis();
response.setDateHeader("Date", now);
response.setDateHeader("Last-Modified", now);
response.setDateHeader("Expires", 0);
//Force IE to recognize MIME type
String fileName = request.getServletPath();
fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
fileName = fileName.substring(0, fileName.indexOf(".")) + ".jnlp";
response.setHeader("Content-Disposition", "Inline; fileName=" + fileName);
%>
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply