Hi... Me had to develop a similar application to download /view the files in browser.. am attaching my servlet code which u might find useful , with all the response headers set correctly. Special care had to be take for IE5.5 as it does'nt really behave as expected.
-----Original Message----- From: Tom Bednarz [mailto:[EMAIL PROTECTED]] Sent: Friday, May 31, 2002 5:43 PM To: Struts Users Mailing List Subject: Re: Nightmare with response header 'content-disposition' Well I fixed my attach(e)ment typo and now with MS IE it asks me to save the file or to open excel. Both do NOT work and an error message appears saying that IE is not able to open the source file or disk. Well, I do NOT generate a file on the web server. I simply create an output stream... Does anybody know what the problem is? With netscape it doesn't work either. There it does not recognise the correct file name, it tries to store a file named as the servlet name. The file size is 0! Opera does not recognise the file name but it you can enter a name and then the correct excel sheet is saved to disk. As I said, its a big browser nightmare. It would be great if somebody could tell me how the header must be formatted to be correctly recognised by all major browsers.... Cheers Thomas ----- Original Message ----- From: "Rajeshwar Rao V" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, May 31, 2002 10:45 AM Subject: RE: Nightmare with response header 'content-disposition' > i think the syntax is wrong!!!Here is the correct syntax.. > > res.setHeader ("Content-Disposition", > "attachment; filename=\"" + _fileName + "\""); > > > and > > why this? > response.addHeader("content-disposition", > "filename="+es.getFileName());-------->remove it..not required. > > -----Original Message----- > From: Tom Bednarz [mailto:[EMAIL PROTECTED]] > Sent: Friday, May 31, 2002 2:10 PM > To: poi - user; struts user list > Subject: Nightmare with response header 'content-disposition' > > > Hi, > > First of all sorry for the cross-posting but I really don't know which is > the correct list for my problem. > > I use Struts and velocity to generate my HTML pages. I use POI to generate > some reports out of database data and other datasources such as CORBA > servers. > > I face the following problem: > > When using struts you usually create actions and forward any type of result > to a jsp or in my case to a velocity template. When I present a query result > as a HTML page, the user finds two links on that pages: 'get as CSV' and > 'get as EXCEL'. I have written a servlet, which transforms data (that I keep > in a session object) into CSV or EXCEL using apache POI. > > This looks as follows for Excel: > > public class transformIntoExcel extends HttpServlet > { > private static final String CONTENT_TYPE = "application/vnd.ms-excel"; > //Initialize global variables > public void init() throws ServletException > { > } > //Process the HTTP Get request > public void doGet(HttpServletRequest request, HttpServletResponse > response) throws ServletException, IOException > { > HttpSession session = request.getSession(false); > response.setContentType(CONTENT_TYPE); > //PrintWriter out = response.getWriter(); > > ExcelSheet es = (ExcelSheet)session.getAttribute("ExcelSheet"); > if (es != null) > { > response.addHeader("content-disposition", "attachement; > filename="+es.getFileName()); > response.addHeader("content-disposition", > "filename="+es.getFileName()); > session.removeAttribute("ExcelSheet"); > ServletOutputStream servletOut = response.getOutputStream(); > es.getWorkbook().write(servletOut); > } > } > //Clean up resources > public void destroy() > { > } > } > > I found out, that the interpretation of the header 'content-disposition' > seems to be absolutely browser dependant. I tried IE 5, 5.5 and 6, NS 6 and > Opera 6. The only correct behaviour I noticed with Opera. It opend a dialog > and asked me where to save the file. It showed a correct file name like > 'MyExelSheet.xls' (Exactly what was returned by es.getFileName() in my code > above) > > Some browsers (mostly microsoft IE) throw an error message saying that the > file could not be found. The file name is in most cases some crap like a > mixture of characters and numbers. Some browsers also display the servlet > name! I did a mapping of the above servlet to 'makeexcel' so some browsers > try to store a file 'makeexcel' without any extension. > > I do something similar with CSV Files (comma separated values). > The content type is set there to > CONTENT_TYPE = "text/comma-separated-values" > This works much better and every browser in every version shows a file save > dialog and proposes the correct file name as I set it in my > content-disposition header. > > I also found many different content types for excel such as > "application/vnd.ms-excel" or "application/x-msexcel" or "application/excel" > > Does anybody know how this works? I like that the user MUST save the file > before opening. Some browsers as M$ IE use to open known file types directly > as OLE objects inside the browser unless the user configures the browser NOT > do do so (usually done for security reasons). IE is a OLE container that > can open most OLE objects directly. I personally hate this behaviour because > it is highly insecure!! > > Any help would be greatly appreciated. > > Thomas > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
DocumentViewer.java
Description: Binary data
**************************Disclaimer************************************ Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' and 'confidential' and intended for use only by the individual or entity to which it is addressed. You are notified that any use, copying or dissemination of the information contained in the E-MAIL in any manner whatsoever is strictly prohibited. ***************************************************************************
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>