Home Answers Viewqa JSP-Servlet Getting an exception

 
 


harini
Getting an exception
1 Answer(s)      3 years and a month ago
Posted in : JSP-Servlet

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 Pages:
Getting Exception
Getting Exception  How to get exception from commented code in java
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
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  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
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 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 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
Exception
Exception  public class FooException extends Exception { public..."); } public void calculate() throws FooException, Exception { try { int.... ex.printStackTrace(); System.exit(1); } catch(Exception ex
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 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
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
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 - 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
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
problem getting password - JavaMail
problem getting password  hi i am trying to get password but igot following error Error sending mail:javax.mail.MessagingException: Could not connect to SMTP host: 192.168.10.14, port: 25;nested exception
exception - MobileApplications
exception  Hi friend, again i am getting exception.Entire code of my program i am sending.Plz suggest me. import javax.microedition.midlet...."); } // System.out.println("hai"); catch (Exception e
Getting garbage value
Getting garbage value  Thank You Sir for helping me out from the problem. Now I'm facing some problem with the value I'm passing to the textfield...=Integer.parseInt(t2, 10); } catch(Exception e) { e.printStackTrace(); } if(t2!=null
Getting garbage value
Getting garbage value  Thank You Sir for helping me out from the problem. Now I'm facing some problem with the value I'm passing to the textfield...); } catch(Exception e) { e.printStackTrace(); } if(t2!=null) { if(t1>
Im not getting validations - Struts
Im not getting validations  I created one struts aplication im using DynaValidations I configured validation.xml and validation-rules.xml also..., HttpServletResponse response) throws ServletException,Exception
Getting error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.
Getting error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.  I am doing project in JSP with database WampServer and glassfish as server...(Exception ex){ %> <% out.println("Unable to connect to database."+ex); } %>
:( I am not getting Problem (RMI)
I am not getting Problem (RMI)  When i am excuting RMI EXAMPLE 3,2 I am getting error daying nested exception and Connect Exception... exception and Connect Exception   RMI Tutorials http
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
j2me exception - MobileApplications
"); } catch (Exception e) { //getting IOException...j2me exception  hai while creating an image i am getting an exception in the below line: public ImageItemMIDlet(){ try
SQL exception, Exhausted ResultSet
SQL exception, Exhausted ResultSet  javax.servlet.ServletException: java.sql.SQLException: Exhausted Resultset iam getting this error messege whenever i run my code. what would be the possible reasons
wlinitialcontextfactory instantiation exception - EJB
_CLASSES then I am not getting any exception and also not getting the result... to execute Client program of simple EJB program its giving me exception like
Java Mail exception - JavaMail
while i am connecting to the Gmail, I am getting the following exception... Whats wrong... I dont know.. How to avoid this exception. The exception
bean creation exception
bean creation exception  hi i am getting exception while running simple spring ioc program Exception in thread "main... path resource [beans.xml]; nested exception is java.io.FileNotFoundException
Getting Textbox data from database
Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown...+"'"); rs.next(); } catch(Exception e){} finally { rs.close(); stmt.close
numberformat exception - Java Beginners
code, but string contains no.s, upto 10 no.s i am getting my requirement, above 10 no.s i am getting NumberFormatException. But in my reqirement textField...)[String is no.s get from textfield], after entering 20 no.s, getting NumberFormat
Getting Textbox data from database
Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown below. type Exception report message description The server encountered
sql exception - JSP-Servlet
sql exception  Dear sir , I am working in a web-based project, In my system it is working fine but at client side getting the following exception so how to resolve this help me... java.sql.SQLException: ORA-28231
Exception - JSP-Servlet
Exception  Hi team, This is Ragavendran.R. I am getting java.lang.StringIndexOutOfBoundsException: String out of range : 6 error while compiling the following program in JSP charting application: Plz reply
Getting 404 errors - Java Beginners
Getting 404 errors  Dear experts, I have embedded a login page inside my landing page - home.jsp. So, at the right-hand column of my page, I...(); }} catch (Exception e) { System.out.println("Error" + e.getMessage
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown...) { sqle.printStackTrace(); } finally { try {stmt.close();} catch (Exception e
Exception in thread "main" java.lang.ClassCastException
Exception in thread "main" java.lang.ClassCastException  I am trying to connect the database. I am stuck with this exception that is getting thrown...) { sqle.printStackTrace(); } finally { try {stmt.close();} catch (Exception e
java runtime exception - JDBC
"); } catch (Exception e) { e.printStackTrace(); } } } i got an exception that classnotfoundexception . how can i remove this exception. i am executing my prgm on command prompt in window 7
JasperException: Exception in JSP
JasperException: Exception in JSP  Hi, I am facing below problem while getting paramater as int from jsp. Same code is working fine for string. Please suggest the way forward. exception
exception
exception  wHEN RUNTIME EXCEPTION CLASS IS SUB OF EXCEPTION CLASS HOW CAN'T HANDLE UNCHECKED EXCEPTION
Exception - JSP-Servlet
Exception  Hi, I am Ragavendran.R.. I am using swiftchart for my chart application.. For this purpose, I am using ServletOutputStream sos=response.getOutputStream(); in my JSP Page. But, I am getting

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.