poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Donahue, Michael" <michael.dona...@pearson.com>
Subject RE: Servlet and Excel
Date Tue, 17 Jan 2006 16:55:05 GMT
Daniele -

Here is a simplified example of the code I used on a Tomcat project.

- MJD

Caveat lector ......
----------------------------------------------------------------------------
-------------------------------------------------
In the Tomcat environment you need to add an entry something like this one
to the MIME Type Mappings section of the Tomcat web.xml file.  (I don't know
if you can put this in your project's web.xml.)

web.xml
    <mime-mapping>
        <extension>xls</extension>
        <mime-type>application/msexcel</mime-type>
    </mime-mapping>


SomeAction.java
    .
    .
    .
    public static final String CONTENT_TYPE_APP_OCTET_STREAM =
"application/octet-stream";
    public static final String CONTENT_TYPE_APP_MSEXCEL = "application/
msexcel";
    .
    .
    .
    protected void doFileDownload(HttpServletResponse response, String
fileName, String filePath, boolean bFlag) {
        try {
            File    file = new File(filePath + fileName);
            String  contentType = null;
            String  headerInfo = null;

            if (file.exists()) {
                if (type) {
                    contentType  = CONTENT_TYPE_APP_OCTET_STREAM;
                    headerInfo   = "attachment; filename=\"" + fileName +
"\"";
                } else {
                    contentType  = CONTENT_TYPE_APP_MSEXCEL;
                    headerInfo   = "inline; filename=\"" + fileName + "\"";
                } // end if

                response.setContentType(contentType);
                response.setHeader("Content-Disposition", headerInfo);
                response.setContentLength((int)file.length());

                // set output stream to the response's output stream
                ServletOutputStream servletOut = response.getOutputStream();

                // now read file
                byte[] dataRead = new byte[(int)file.length()];
                FileInputStream  fileIn = new FileInputStream(file);

                // read in byte data from file and store in byte array
                fileIn.read(dataRead, 0, (int)file.length());

                // close file
                if (fileIn != null) {
                    fileIn.close();
                } // end if

                // write the file to output stream
                servletOut.write(dataRead);

                // flush the output stream
                servletOut.flush();
            }
            else
            {
                // TODO: handle File Not Found error here
            } // end if
        }
        catch (Exception ex)
        {
            // TODO: handle Exception here
        }
    }
    .
    .
    .

-----Original Message-----
From: Vaccari, Daniele [mailto:Daniele.Vaccari@provincia.bz.it] 
Sent: Tuesday, January 17, 2006 1:36 AM
To: POI Users List
Subject: R: Servlet and Excel

Hi,
I need to display the excel file into the browser in a way that the browser
shows the tool bar of Excel, it's fine if it occupies the whole screen. I
need also an example to send the excel file for download.

Thank you
Daniele

-----Messaggio originale-----
Da: Donahue, Michael [mailto:michael.donahue@pearson.com] 
Inviato: venerdì 13 gennaio 2006 17.10
A: 'POI Users List'
Oggetto: RE: Servlet and Excel


Can you explain what you mean by "responding with a jsp page" a little more.
I have some code that will send back the spreadsheet into an IE browser for
display, but it wants the whole screen.  I can also send it as a file for
download.

-----Original Message-----
From: Vaccari, Daniele [mailto:Daniele.Vaccari@provincia.bz.it] 
Sent: Friday, January 13, 2006 2:28 AM
To: poi-user@jakarta.apache.org
Subject: Servlet and Excel

Hi 
 
I need to find an example on how to produce an Excel file from a servlet and
how to send it to the user responding with a jsp page. Does anyone know
where can I find a similar example?
 
Thank you
Daniele

****************************************************************************

This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/


---------------------------------------------------------------------
To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/

**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message