-
Cannot Open Excel file in Browser. (3 messages)
- Posted by: Azghar Baig
- Posted on: July 04 2008 06:50 EDT
Hi I have a class where the following fuction is written: ================================================ public String getMyCSV() { HttpServletResponse Response; try { Response = (HttpServletResponse)getExternalContext().getResponse(); ServletOutputStream outs = Response.getOutputStream(); Response.setContentType("application/vnd.ms-excel"); Response.setHeader("Content-Disposition", "attachment; filename=\"log.csv\""); Response.setHeader("Cache-Control", "public"); Response.setHeader("pragma", ""); try { outs.print(getCSVOutput()); } catch (IOException ioe) { debugLog("Error exporting file", ioe); } ---------------------------------------> I have another file which is accessed in the browser to access this function: -------> Observed: when this JSP file is accessed i get the following error: Exception occured while loading the page: Servlet response already use stream, Writer not possible. I was suspecting the following: the mime-mapping was not available in the web.xml so i added the following: xls application/vnd.ms-excel I would be glad if someone could give me some advice on this. Regards BaigThreaded Messages (3)
- Re: Cannot Open Excel file in Browser. by Jyothish John on July 07 2008 07:32 EDT
- Still facing problems: by Azghar Baig on July 08 2008 11:47 EDT
- Problem sorted. by Azghar Baig on July 10 2008 12:56 EDT
-
Re: Cannot Open Excel file in Browser.[ Go to top ]
- Posted by: Jyothish John
- Posted on: July 07 2008 07:32 EDT
- in response to Azghar Baig
First of All JSF/ JSP should render HTML or character data only;) Without your funny JSF bit, can you try Again there is a mistake in your method, Response = (HttpServletResponse)getExternalContext().getResponse(); ServletOutputStream outs = Response.getOutputStream(); Response.setContentType("application/vnd.ms-excel"); Response.setHeader("Content-Disposition", "attachment; filename=\"log.csv\""); Response.setHeader("Cache-Control", "public"); Response.setHeader("pragma", ""); .... .... then your code is printing the file data to the OutputStream, outs.print(getCSVOutput()); and then you are retruning a String ? . To make things a bit easier, Write your stuff inside a servlet and pump the data to the ServletOutputStream. -
Still facing problems: [ Go to top ]
- Posted by: Azghar Baig
- Posted on: July 08 2008 11:47 EDT
- in response to Azghar Baig
and put WHEN I REMOVED THE HTAG Exception occured while loading the page: Unable to compile class for JSP An error occurred at line: 11 in the jsp file: /viewer/faces/faults/logReportExport.jsp Generated servlet error: logReport.exportToCSV cannot be resolved or is not a type --------------------------> -
Problem sorted.[ Go to top ]
- Posted by: Azghar Baig
- Posted on: July 10 2008 12:56 EDT
- in response to Azghar Baig
Sorted the issue. The Rich Faces Filter was the problem source which other application was using, and was pointing to Faces Servlet. I changed it to url-pattern to point to specific application. Thanks once again for your help.