Tuesday, August 17, 2004

jDev: .JNLP with IExplorer mime type error

sun post

Re: Invalid Argument Error
Author: bghuber
In Reply To: Re: Invalid Argument Error Apr 6, 2004 6:30 PM

Reply 7 of 8


Thanks for the useful info on this problem - but using a JSP to launch a JNLP creates another problem on IE.

Since IE guesses at mime types instead of using the server-sent type, IE prompts for a handler for type "JSP_AUTO_FILE" when using a jsp to launch a JNLP script. Even when deselecting "Always ask for this type of file" IE6 continues to ask every time the jsp link is clicked. Presumably it is using the file extension instead of the server-sent mime type of

response.setContentType ("application/x-java-jnlp-file");

in my JSP (which works perfectly on mozilla). Has anyone found a workaround for this?

More info on IE mime-type "guessing"-

http://support.microsoft.com/default.aspx?sd=msdn&scid=kb;en-us;293336


Re: Invalid Argument Error
Author: markabrown
In Reply To: Re: Invalid Argument Error Aug 4, 2004 1:20 PM

Reply 8 of 8


Thanks to the above post, I found a workaround for IE. In your JSP code for dynamically building the JNLP tag, add the following code:


// this line is necessary to force MS Internet Explorer to recognize the MIME type
String fileName = request.getServletPath();
fileName = fileName.substring(fileName.lastIndexOf("/") + 1);
fileName = fileName.substring(0, fileName.indexOf(".")) + ".jnlp";
response.addHeader("Content-Disposition", "Inline; fileName=" + fileName);


The key is in the way IE determines the MIME type. Since the Content-Type is set to application/x-java-jnlp, IE thinks it should have primarily binary content. Since the file actually has text/xml content IE sees a discrepancy and decides to look it up in the registry by file extension (ie. JSP). This doesn't match a JSP type so IE complains that it doesn't know what to do with it. By adding the above code, you've overridden the filename in the browser cache so when it gets to the step above of getting the file extension, it uses .jnlp instead of .jsp. It finds the registry entry for .jnlp and launches webstart.

Hope this helps,
Mark Brown

No comments: