aspose file tools
The moose likes Other Open Source Projects and the fly likes Export to Excel via a servlet with POI not working under internet explorer 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Reply Bookmark "Export to Excel via a servlet with POI not working under internet explorer 6" Watch "Export to Excel via a servlet with POI not working under internet explorer 6" New topic
Author

Export to Excel via a servlet with POI not working under internet explorer 6

James Blarney
Greenhorn

Joined: Oct 02, 2009
Posts: 10
One of our customers is complaining about not being able to export to excel when using internet explorer. I did some research on the issue and it goes back to something called apache POI. POI claims that you have to change your code:

from Apache POI FAQ: http://poi.apache.org/faq.html

The problem usually manifests itself as the junk characters being shown on screen. The problem persists even though you have set the correct mime type.
The short answer is, don't depend on IE to display a binary file type properly if you stream it via a servlet. Every minor version of IE has different bugs on this issue.
The problem in most versions of IE is that it does not use the mime type on the HTTP response to determine the file type; rather it uses the file extension on the request. Thus you might want to add a .xls to your request string. For example http://yourserver.com/myServelet.xls?param1=xx. This is easily accomplished through URL mapping in any servlet container. Sometimes a request likehttp://yourserver.com/myServelet?param1=xx&dummy=file.xls is also known to work.
To guarantee opening the file properly in Excel from IE, write out your file to a temporary file under your web root from your servelet. Then send an http response to the browser to do a client side redirection to your temp file. (Note that using a server side redirect using RequestDispatcher will not be effective in this case)
Note also that when you request a document that is opened with an external handler, IE sometimes makes two requests to the webserver. So if your generating process is heavy, it makes sense to write out to a temporary file, so that multiple requests happen for a static file.
None of this is particular to Excel. The same problem arises when you try to generate any binary file dynamically to an IE client. For example, if you generate pdf files using FOP, you will come across many of the same issues.

The POI mailing list says that I have to do this: http://www.mail-archive.com/poi-user@jakarta.apache.org/msg08720.html

Hi Dragen,

We serve POI written XLS all the time through TOmcat 4.1.31 - we learned the hard way the following:
Do not serve through a JSP - write a Servlet:

(1) JSP is supposed to be TEXT only.
(2) In JSP it is easy to insert a space in your output before setting the header and that makes the output have mimetype=text/plain.


Then your url is /exportxls?parms=whatever

When you open your Excel file from the Web in IE - DO NOT let it open it in the Browser - Save it and Open. If anyones knows an easy ubiquitous way to unset that, I'd love to know.
If you use application/octet-stream and allow IE to open in the browser then you will start to have trouble with binary files that are served that way ...
Regards,
Dave Fisher



How do I implement the advice above into this file: ExcelResult.java I already added those changes to the web.xml file.




This is my revised code. Keep in mind, im kind of a noob.


Ill be happy to provide more information as requested


Tuan Th
Greenhorn

Joined: Nov 19, 2009
Posts: 1
anyone know how to use POI with more intelligent?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3268

Tuan,

Welcome to Javaranch! Can you provide more details, I'm not sure what you're trying to ask!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Export to Excel via a servlet with POI not working under internet explorer 6
 
Similar Threads
download zipped excel help!!!
Exporting some data to excel
NullPointerException
Export to Excel not working with Internet Explorer HSSF and POI
Writing on excel file using POI