Getting an exception

Getting an exception

sir i changed to that ie
InputStream myInput1 = new FileInputStream(fileName);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput1);

but when i click on a browse button and attached a file and then click on a read button to read a file it is displaying a new file instead of showing a what i have attached(file), in server console i m gtting a following exception please help me sir if an changes tel me sir

thanks in advance..



java.io.IOException: Invalid header signature; read 0x3109696E69726168, expected
0xE11AB1A1E011CFD0
at org.apache.poi.poifs.storage.HeaderBlockReader.<init>(HeaderBlockRead
er.java:107)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSyste
m.java:151)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:3
17)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:2
98)
at com.antares.Action.ReadExcelFile.ReadCSV(ReadExcelFile.java:24)
at org.apache.jsp.jsp.ReadExcelFile_jsp._jspService(ReadExcelFile_jsp.ja
va:70)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
42)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
at java.lang.Thread.run(Thread.java:595)





following is m code sir


//ReadExcelFile .java
package com.antares.Action;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Vector;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;



public class ReadExcelFile {

// @SuppressWarnings("unchecked")
public static Vector ReadCSV(String fileName) {
Vector cellVectorHolder = new Vector();

try {
FileInputStream myInput = new FileInputStream(fileName);
InputStream myInput1 = new FileInputStream(fileName);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput1);
HSSFSheet mySheet = myWorkBook.getSheetAt(0);

Iterator rowIter = mySheet.rowIterator();

while (rowIter.hasNext()) {
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector cellStoreVector = new Vector();
while (cellIter.hasNext()) {
HSSFCell myCell = (HSSFCell) cellIter.next();
cellStoreVector.addElement(myCell);
}
cellVectorHolder.addElement(cellStoreVector);
}
} catch (Exception e) {
e.printStackTrace();
}
return cellVectorHolder;
}

//@SuppressWarnings({ "unused", "unchecked" })
public static void printCellDataToConsole(Vector dataHolder) {

for (int i = 0; i < dataHolder.size(); i++) {
Vector cellStoreVector = (Vector) dataHolder.elementAt(i);
for (int j = 0; j < cellStoreVector.size(); j++) {
HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
String stringCellValue = myCell.toString();
System.out.print(stringCellValue + "\t");
}
System.out.println();
}
}

}


//excel.jsp

<%@ page language="java" import="java.io.*" %>
<form method="post" action="success.jsp">
<p><font color="#800000" size="5">Enter XLS file name:</font>
<input type="text" name="filename" size="20"></p>
<p><input type="submit" value="Create"
onclick="document.location='success.jsp';"/>
</p>
</form>
<form method="post" action="ReadExcelFile.jsp">
<p><font color="#800000" size="5">Enter XLS File Name To Read:</font>
<input type="file" name="filename" size="20"></p>
<p><input type="submit" value="Click Here To Read"
onclick="document.location='ReadExcelFile.jsp';"/>
</p>
</form>


//ReadexcelFile.jsp
<%@ page contentType="application/vnd.ms-excel"%>
<%@ page import="com.antares.Action.ReadExcelFile"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.util.Vector"%>


<%
ReadExcelFile readExcelFile = new ReadExcelFile();

String fileName = request.getParameter("filename");
System.out.println("***file name is " + fileName);
Vector dataHolder = readExcelFile.ReadCSV(fileName);
ReadExcelFile.printCellDataToConsole(dataHolder);
%>
View Answers

April 22, 2010 at 5:38 PM

Hi Friend,

Try the following code:

1)excel.jsp:

<%@ page language="java" import="java.io.*" %>
<form method="post" action="success.jsp">
<p><font color="#800000" size="5">Enter XLS file name:</font>
<input type="text" name="filename" size="20"></p>
<p><input type="submit" value="Create"
onclick="document.location='success.jsp';"/>
</p>
</form>
<form method="post" action="ReadexcelFile.jsp">
<p><font color="#800000" size="5">Enter XLS File Name To Read:</font>
<input type="text" name="filename" size="20"></p>
<p><input type="submit" value="Click Here To Read"/>
</p>
</form>

2)ReadexcelFile.jsp:

<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import=" org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@page import=" org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@page import=" org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@page import=" org.apache.poi.hssf.usermodel.HSSFCell"%>
<%
String filename = request.getParameter("filename");
if (filename != null && !filename.equals("")) {
try{
FileInputStream fs =new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(fs);
for (int k = 0; k < wb.getNumberOfSheets(); k++){
HSSFSheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
for (int r = 0; r < rows; r++){
HSSFRow row = sheet.getRow(r);
if (row != null) {
int cells = row.getPhysicalNumberOfCells();
%>
<br>
<%
for (short c = 0; c < cells; c++) {
HSSFCell cell = row.getCell(c);
if (cell != null) {
String value = null;
switch (cell.getCellType()){

case HSSFCell.CELL_TYPE_FORMULA :
value = "FORMULA ";
break;

case HSSFCell.CELL_TYPE_NUMERIC :
value = ""+cell.getNumericCellValue();
break;

case HSSFCell.CELL_TYPE_STRING :
value = cell.getStringCellValue();
break;

default :
}
%>
<%= value %>
<%
}
}
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}

}
%>

Hope that it works.
Thanks









Related Tutorials/Questions & Answers:
Getting Exception
Getting Exception  How to get exception from commented code in java
Getting exception in hello world
Getting exception in hello world  I run your hibernate5 "hello world" program. But, getting an exception: ERROR: Table 'mydb.employee' doesn't exist Exception in thread "main" javax.persistence.PersistenceException
Advertisements
Getting exception in hello world
Getting exception in hello world  I run your hibernate5 "hello world" program. But, getting an exception: ERROR: Table 'mydb.employee' doesn't exist Exception in thread "main" javax.persistence.PersistenceException
Getting an exception - JSP-Servlet
Getting an exception  Dear Sir , While sending a mail am getting an following exception javax.mail.MessagingException: 554 mail server permanently rejected message (#5. 3.0)so how to over come from this please help
Getting an exception - JSP-Servlet
Getting an exception  thanks sir for u r reply ,but i already added that jar file sir even though i m getting an exception sir please help me sir ... thanks in advance..  Hi Friend, You can do one thing, replace
Getting an exception - JSP-Servlet
Getting an exception   sir i am Getting following exception when...(cellStoreVector); } } catch (Exception e) { e.printStackTrace... running it will throwing an exception please help me sir thanks
Getting an exception - JSP-Servlet
Getting an exception  sir i m Getting an following exception while... sending message; nested exception is: java.io.FileNotFoundException...); }catch(Exception e){ System.out.println("Send Mail exception
I am getting this exception
I am getting this exception   Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java
Getting an exception - JSP-Servlet
Getting an exception  Dear sir,while executing this code i am getting... of a is " + f); } } //following is an exception org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/newTestMES3.jsp at line
Getting an exception - JSP-Servlet
Getting an exception  sir i changed to that ie InputStream myInput1... exception please help me sir if an changes tel me sir thanks in advance...); } cellVectorHolder.addElement(cellStoreVector); } } catch (Exception e
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
Getting exception in Assocation & Join. - Hibernate
Getting exception in Assocation & Join.  select product0_.id as id0...) exception setting property value with CGLIB (set hibernate.cglib.use_reflection... org.hibernate.PropertyAccessException: exception setting property value with CGLIB
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
getting classnotfound exception while running login application
getting classnotfound exception while running login application  hi, I am getting Error creating bean with name 'urlMapping' defined... [TypedStringValue: value [/login.html], target type [null]]; nested exception
Getting Exception on UseDefinedException sample program - Please help me how to resolve
Getting Exception on UseDefinedException sample program - Please help me how to resolve  class UseDefinedException extends Exception{ String msg...); } } } Hi, I tried above code but getting Exception : MyException cannot
try to execute this code getting class cast exception, please resolve it.
try to execute this code getting class cast exception, please resolve it.  package test; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; public class Over { static int k
using spring rmi+maven but i am getting this exception
using spring rmi+maven but i am getting this exception  D:\Nexustool... --- java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception
Exception
Exception  public class FooException extends Exception { public..."); } public void calculate() throws FooException, Exception { try { int.... ex.printStackTrace(); System.exit(1); } catch(Exception ex
exception
exception  wHEN RUNTIME EXCEPTION CLASS IS SUB OF EXCEPTION CLASS HOW CAN'T HANDLE UNCHECKED EXCEPTION
exception
exception  chek in and check out exception in java   Please visit the following link: Checked and Unchecked Exception
exception
arguments are not equalto two,throw a user defined exception "invalid parameter exception" ,otherwise display the two parameters.   Here is an example... is not equal to two then invalid parameter exception is thrown ,otherwise display the two
exception
exception  what is the use of catch block even though we have predefined exception object
exception
exception  example for numberformat exception   Hi Friend, Try the following code:ADS_TO_REPLACE_1 class NumberFormatExceptionEx...); } catch(Exception e){ System.out.println(e
exception
defined checked exception ââ?¬Å?InvalidCharcterFoundExceptionââ?¬Â? and creater a block of codes that will handle the exception
Exception
Exception  whis is the Arithmetic Exception in java? or define Arithmetic Exception with exp?   Arithmetic Exception occurs, when you divide a number by zero. Example public class TryCatch { public static void main
Exception
Exception   I was creating a table dynamically but it shows exception i.e shown down Suplier created0 Suplier created0 Suplier created0 Product created0 Product created0 Product created0 Product created0 could not fetch initial
exception
user defined unchecked exception  can we create user defined unchecked exceptions? if so what is the exact use of it in real time?   Please visit the following links: http://www.roseindia.net/java/java-exception/user
exception
exception  Identify the reason for SQLException exception, which is encountered when the developer tries to run the following code snippet to insert..."); ps.executeUpdate(); } catch(Exception e
Getting NumberFormatException
Getting NumberFormatException  Hello Sir, I'm using Integer.parseInt... also used Integer.parseInt(String str, int radix) but it also throws the exception... it in a JSP it continuously throws the exception. below is the code I used. Please
Exception - Struts
Exception - java.lang.reflect.InvocationTargetException   java.lang.reflect.InvocationTargetException i am getting the foregoing error ...can anyone...: java.lang.reflect.InvocationTargetException: This is a checked exception that extends Exception Class thrown
exception - Struts
exception  Hi, While try to upload the example given by you in struts I am getting the exception javax.servlet.jsp.JspException: Cannot...: Exception in JSP: /FileUpload.jsp:10 7: 8: 9: 10: 11: 12: 13
getting variables
getting variables   how to get variables from servlet program to webservice program
Getting an error :(
Getting an error :(  I implemented the same code as above.. But getting this error in console... Console Oct 5, 2012 10:18:14 AM... loadOnStartup SEVERE: Servlet /SpringMVC threw load() exception
exception handling
exception handling  explain about exception handling
Exception in thread
Exception in thread   Hi, I have created a java file for sending... but when i am trying to run following command I am getting an error. java -cp D:\mail.jar SendMailTLSDFC Exception in thread "main" java.lang.NoClassDefFoundError
getting the emplo
getting the emplo   I have one table "EMPLOYEEMASTER" contains 'emp id', 'employee name' for eg: emp id employee name... kumar i want the sql statement for getting like
Exception handling
Exception handling  how to resolve file not found error exception
Exception in jsf application
Exception in jsf application  when i am running application i am getting org.apache.commons.logging.LogConfigurationException and HTTP Status 404 -The requested resource () is not available Exception so i want to know reason
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling
exception handling
exception handling  what is the information of exception handling?   Have a look at the following link: Java Exception Handling

Ads