0

I have a JSF2 application linking to static Excel files on the server's filesystem. The link is a simple html like this:

<a href="#{bean.getExcelLink(auction)}">Excel File</a>

This works well with Chrome and Firefox, and also on IE when the application is running in Tomcat on my local Windows 7 machine. But when on the staging environment, which is Linux with Jboss AS 7.0.1 Final, IE tries to open the Excel file in its own window and produces a bunch of garbage characters.

Again, the problem is only on IE when the application is running on Linux with Jboss AS.

Any idea on what's going on and how to solve it?

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
Herzog
  • 923
  • 1
  • 14
  • 28

1 Answers1

1

Apparently the response content type is wrong. Given the fact that it fails in Linux but succeeds in Windows, that can only mean that a platform-specific mime type mapping is been used to determine the content type instead of the webapp/server-specific mime type mapping (the Linux machine of course doesn't have MS Office installed, so it's not well aware of mime type of .xls or .xlsx files). This can in turn only mean that you're not directly linking to it, but using a generic servlet to stream the file.

If this is true, then you should actually be using ServletContext#getMimeType() to determine the content type based on the file extension instead of maybe URLConnection#guessContentTypeFromName() which uses the platform-specific mime type mapping. The server has in its own web.xml a predefinied list of all default mime types in flavor of <mime-mapping> entries which you can override/extend in webapp's own web.xml.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for looking into this, BalusC. I am linking directly. The link from the "view source" looks like this: http://server_name:8080/res/32-06Feb2012.154159-uploadLots-test%20lots-3.xls. And this problem happens only with IE. If I am to go through the servelet should the code do similar work to the one in your answer here http://stackoverflow.com/questions/8991478/action-link-and-download-link-in-one? – Herzog Feb 06 '12 at 15:25
  • If you're linking directly, then that would then be a bug in JBoss server itself (which I actually wouldn't expect). Can you please show the response headers it returned on the request to the XLS file? – BalusC Feb 06 '12 at 15:27
  • When I do that I get a whole lot of garbage under the HTML tab of the Developer Tools (basically the same as what's on the page itself.) The Script tab has this, ÐÏࡱá which I doubt is helpful. Any other place I should go to? btw my browser is IE8. Should I update to 9? – Herzog Feb 06 '12 at 15:56
  • This is from chrome: Accept-Ranges:bytes Content-Length:17408 Date:Mon, 06 Feb 2012 16:26:52 GMT ETag:W/"17408-1328543185000" Last-Modified:Mon, 06 Feb 2012 15:46:25 GMT Server:Apache-Coyote/1.1 – Herzog Feb 06 '12 at 16:31
  • 1
    So, there's no `Content-Type` header at all? This is definitely not right. Compare it to your local JBoss instance. If the JBoss version at staging is exactly the same, then it's perhaps caused by a proxy in front of JBoss (e.g. Apache HTTPD or so). Consult the serveradmin and report this issue. – BalusC Feb 06 '12 at 16:32