これが私のサーブレットクラスです
package com.zaggle;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class FirstServlet
*/
public class FirstServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FirstServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String[] data;String val=null,name;
name=request.getParameter("excelsheet");
System.out.println(name);
response.setContentType("text/html");
UploadExcel ex= new UploadExcel();
data=ex.procedure(name);
System.out.println(name);
request.setAttribute("val", data);
System.out.println(val);
String destination="/NewFile1.jsp";
RequestDispatcher rd=getServletContext().getRequestDispatcher(destination);
//doGet(request, response);
rd.forward(request, response);
}
}
これが、サーブレットクラスで使用している通常のJavaクラスです。
package com.zaggle;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.RestoreAction;
import org.apache.poi.hssf.record.formula.functions.Goto;
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 UploadExcel {
public String[] procedure(String filename) {
// Scanner scanner = new Scanner(System.in);
//System.out.println("Please enter a filename with extention to upload");
String fileName = "C:\\"+filename;//+scanner.nextLine();
String[] dataHolder = ReadCSV(fileName);
// printCellDataToConsole(dataHolder);
return dataHolder;
}
public static void printCellDataToConsole(Vector dataHolder) {
// TODO Auto-generated method stub
for(int i=0;i<dataHolder.size();i++)
{
Vector column=(Vector)dataHolder.elementAt(i);
for (int j = 0; j < column.size(); j++) {
HSSFCell myCell = (HSSFCell) column.elementAt(j);
String stringCellValue = myCell.toString();
System.out.print(stringCellValue + "\t");
}
System.out.println();
}
}
public static String[] ReadCSV(String fileName) {
// TODO Auto-generated method stub
Vector cellVectorHolder = new Vector();
String[] col = null;
try {
FileInputStream myInput = new FileInputStream(fileName);
POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
while (rowIter.hasNext()) {
HSSFRow myRow = (HSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
Vector column = new Vector();
while (cellIter.hasNext()) {
HSSFCell myCell = (HSSFCell) cellIter.next();
column.addElement(myCell);
}
col=column.toString().split(" ");
cellVectorHolder.addElement(column);
}
} catch(IOException ie)
{
System.err.println("Please enter a valid input");
}
catch (Exception e) {
e.printStackTrace();
}
//return cellVectorHolder;
return col;
}
}
実行すると、次のようなエラーが発生します
タイプ例外レポート
メッセージ
説明サーバーで内部エラー()が発生したため、この要求を実行できませんでした。
例外
javax.servlet.ServletException:サーブレットの実行により例外がスローされました
根本的な原因
java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/POIFSFileSystem
com.zaggle.UploadExcel.ReadCSV(UploadExcel.java:52)
com.zaggle.UploadExcel.procedure(UploadExcel.java:24)
com.zaggle.FirstServlet.doPost(FirstServlet.java:42)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
なぜこのエラーが発生するのですか。誰か助けてもらえますか?