Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Not able to complie JSP file.

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have the following code in my jsp , when i try to execute it , i get an exception in tomcat that it was not able to compile it as
it was not able to resolve the class name or Type:
HSSFWorkbook ,HSSFRow , HSSFCell and POIFSFileSystem
I have these files in my build path (class path) and i can execute the code below (exactly same) if i execute it in a java class instead of jsp.
it runs and gives me the result as well, but in scriptlet it does not.
what am i doing wrong?
-Thanks.

------------------------------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.io.*,org.apache.poi.hssf.usermodel.*,org.apache.poi.poifs.filesystem.*" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
FileInputStream fileIn = null;
FileOutputStream fileOut = null;

try
{
fileIn = new FileInputStream("c:\\MYEXCEL.xls");
org.apache.poi.poifs.filesystem.POIFSFileSystem fs = new POIFSFileSystem(fileIn);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
int NO_OF_ROWS=sheet.getPhysicalNumberOfRows();

HSSFRow row ;
HSSFCell cell ;

for(int i=1;i<NO_OF_ROWS;i++){
row = sheet.getRow(i);
for(int j=0;j<=3;j++){
cell=row.getCell((short)j);
if(j==0){
out.print("Name: "+ cell.getRichStringCellValue()+ " ");
continue;
}

out.print(cell.getNumericCellValue()+" ");
}
out.println("\n");
}




// Write the output to a file

}
finally
{
if (fileOut != null)
fileOut.close();
if (fileIn != null)
fileIn.close();
}
%>


</body>
</html>
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The POI jar file needs to be in the WEB-INF/lib directory of your web application.
 
prakash chauhan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks it worked.
 
Have you no shame? Have you no decency? Have you no tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!