Cannot Open Excel file in Browser.

Discussions

Web tier: servlets, JSP, Web frameworks: Cannot Open Excel file in Browser.

  1. Cannot Open Excel file in Browser. (3 messages)

    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: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> -------> 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 Baig

    Threaded Messages (3)

  2. 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.
  3. Still facing problems: [ Go to top ]

    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 -------------------------->
  4. Problem sorted.[ Go to top ]

    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.