Well data is sent to you following multipart/form-data you need to use something like commons-fileupload (http://jakarta.apache.org/commons/fileupload/) to read the file sent to you from the browser.
Tom
Natu, Ashlesha [IT] wrote:
> Hi,
>
> I am new to POI. I am trying to upload an excel sheet and read it using POI.
> My html code is:
> <form name="frmNTest" enctype="MULTIPART/FORM-DATA" method="post"
> action="test.jsp">
> <input type=hidden name=hfrmID value="frmTest">
> <input type=hidden name=hfrmActionID value="uploadFiletoServer">
> <table width="98%" border=0>
> <tr>
> <td>Select File</td>
> <td><input type="file" name="updfilename">
> </td>
> </tr>
>
> <tr>
> <td colspan="2"><div align="center">
> <input type="submit" name=Submit value="Upload">
> </div></td>
> </tr>
> </table>
>
> **************************
> My server side code is: (test.jsp)
> <%
> UploadFile up = new UploadFile();
> up.doUpload(request,response);
> %>
> ********************************
> import java.io.*;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import javax.servlet.ServletInputStream;
> import org.apache.poi.hssf.util.*;
> import org.apache.poi.hssf.eventmodel.*;
> import org.apache.poi.hssf.eventusermodel.*;
> import org.apache.poi.hssf.dev.*;
> import org.apache.poi.hssf.usermodel.*;
> import org.apache.poi.poifs.filesystem.*;
> import java.io.FileInputStream;
> import java.io.InputStream;
>
> public class UploadFile {
>
> public void doUpload(HttpServletRequest request, HttpServletResponse
> response) throws IOException
> {
> try
> {
> ServletInputStream is = request.getInputStream();
> InputStream ins = (InputStream)is;
> POIFSFileSystem fs = new POIFSFileSystem(ins);
> HSSFWorkbook wb = new HSSFWorkbook(fs);
> HSSFSheet sheet = wb.getSheetAt(0);
> HSSFRow row = sheet.getRow(1);
> HSSFCell cell = row.getCell((short)0);
> String c1 = cell.getStringCellValue();
> }
> catch(IOException io)
> {
> LCMLogger.log("io error = " + io.toString());
> }
> }
> }
> *******************
> I am getting the following exception:
> java.io.IOException: Invalid header signature; read 3255307777713450285,
> expected -2226271756974174256
> **********************
> If I hard copy the filename instead as below, then the code works fine and I
> can read the cell contents.
> POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("Test.xls"));
>
> Please can anyone help me in this matter? Why doesn't the POIFSFileSystem
> object get created when I pass an input stream to it?
>
> thanks, AN
>
>
signature.asc
Description: OpenPGP digital signature
