<%@page import="java.io.File"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Excel Web View</title>
<%@ page import="java.io.FileInputStream" %>
<%@ page import="org.apache.poi.ss.usermodel.DataFormatter" %>
<%@ page import="org.apache.poi.xssf.usermodel.*" %>
<%@page import="org.apache.poi.hssf.usermodel.*"%>
</head>
<body>
<table border="1">
<%
String filename="C:"+ File.separator + "Users" + File.separator + "Yatin Relhan" + File.separator +"Downloads" + File.separator + "CSV_Database_of_First_Names.xls";
String extension = "";
int i = filename.lastIndexOf('.');
if (i >= 0) {
extension = filename.substring(i+1);
}
if(extension !=null && extension.contains("xlsx"))
{
if(filename != null && !filename.equals("")){
try{
FileInputStream fs =new FileInputStream(filename);
XSSFWorkbook wb = new XSSFWorkbook (fs);
for(int k = 0; k < wb.getNumberOfSheets(); k++){
XSSFSheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
DataFormatter formatter = new DataFormatter();
for(int r = 0; r < rows; r++){
XSSFRow row = sheet.getRow(r);
int cells = row.getPhysicalNumberOfCells();
%>
<tr>
<%
for(int n=0;n<cells;n++)
{
%>
<td>
<%
formatter.formatCellValue(row.getCell(n));
%>
</td>
<%
}
%></tr><%
}
}
}
catch(Exception e){
System.out.println(e);
}
}
}
else {
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();
DataFormatter formatter = new DataFormatter();
for(int r = 0; r < rows; r++){
HSSFRow row = sheet.getRow(r);
int cells = row.getPhysicalNumberOfCells();
%>
<tr>
<%
for(int n=0;n<cells;n++){
%>
<td>
<%
formatter.formatCellValue(row.getCell(n));
%>
</td>
<%
}
%>
</tr>
<%
}
}
}
catch(Exception e){
System.out.println(e);
}
}
}
%>
</table>
</body>
</html>
我必须遵循我试图在Tomcat服务器上运行的JSP文件。我已导入必要的JAR但我收到以下错误
An error occurred at line: [16] in the generated java file: [C:\EclipseWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Hi\org\apache\jsp\NewFile_jsp.java]
Only a type can be imported. org.apache.poi.ss.usermodel.DataFormatter resolves to a package
An error occurred at line: [33] in the jsp file: [/NewFile.jsp]
XSSFWorkbook cannot be resolved to a type
30: try{
31:
32: FileInputStream fs =new FileInputStream(filename);
33: XSSFWorkbook wb = new XSSFWorkbook (fs);
34: for(int k = 0; k < wb.getNumberOfSheets(); k++){
35: XSSFSheet sheet = wb.getSheetAt(k);
36: int rows = sheet.getPhysicalNumberOfRows();
An error occurred at line: [33] in the jsp file: [/NewFile.jsp]
XSSFWorkbook cannot be resolved to a type
30: try{
31:
32: FileInputStream fs =new FileInputStream(filename);
33: XSSFWorkbook wb = new XSSFWorkbook (fs);
34: for(int k = 0; k < wb.getNumberOfSheets(); k++){
35: XSSFSheet sheet = wb.getSheetAt(k);
36: int rows = sheet.getPhysicalNumberOfRows();
An error occurred at line: [35] in the jsp file: [/NewFile.jsp]
XSSFSheet cannot be resolved to a type
32: FileInputStream fs =new FileInputStream(filename);
33: XSSFWorkbook wb = new XSSFWorkbook (fs);
34: for(int k = 0; k < wb.getNumberOfSheets(); k++){
35: XSSFSheet sheet = wb.getSheetAt(k);
36: int rows = sheet.getPhysicalNumberOfRows();
37: DataFormatter formatter = new DataFormatter();
38:
An error occurred at line: [37] in the jsp file: [/NewFile.jsp]
DataFormatter cannot be resolved to a type
34: for(int k = 0; k < wb.getNumberOfSheets(); k++){
35: XSSFSheet sheet = wb.getSheetAt(k);
36: int rows = sheet.getPhysicalNumberOfRows();
37: DataFormatter formatter = new DataFormatter();
38:
39: for(int r = 0; r < rows; r++){
40: XSSFRow row = sheet.getRow(r);
An error occurred at line: [37] in the jsp file: [/NewFile.jsp]
DataFormatter cannot be resolved to a type
34: for(int k = 0; k < wb.getNumberOfSheets(); k++){
35: XSSFSheet sheet = wb.getSheetAt(k);
36: int rows = sheet.getPhysicalNumberOfRows();
37: DataFormatter formatter = new DataFormatter();
38:
39: for(int r = 0; r < rows; r++){
40: XSSFRow row = sheet.getRow(r);
An error occurred at line: [40] in the jsp file: [/NewFile.jsp]
XSSFRow cannot be resolved to a type
37: DataFormatter formatter = new DataFormatter();
38:
39: for(int r = 0; r < rows; r++){
40: XSSFRow row = sheet.getRow(r);
41:
42: int cells = row.getPhysicalNumberOfCells();
43: %><tr>
An error occurred at line: [65] in the jsp file: [/NewFile.jsp]
HSSFWorkbook cannot be resolved to a type
62: if(filename != null && !filename.equals("")){
63: try{
64: FileInputStream fs =new FileInputStream(filename);
65: HSSFWorkbook wb = new HSSFWorkbook (fs);
66: for(int k = 0; k < wb.getNumberOfSheets(); k++){
67: HSSFSheet sheet = wb.getSheetAt(k);
68: int rows = sheet.getPhysicalNumberOfRows();
An error occurred at line: [65] in the jsp file: [/NewFile.jsp]
HSSFWorkbook cannot be resolved to a type
62: if(filename != null && !filename.equals("")){
63: try{
64: FileInputStream fs =new FileInputStream(filename);
65: HSSFWorkbook wb = new HSSFWorkbook (fs);
66: for(int k = 0; k < wb.getNumberOfSheets(); k++){
67: HSSFSheet sheet = wb.getSheetAt(k);
68: int rows = sheet.getPhysicalNumberOfRows();
An error occurred at line: [67] in the jsp file: [/NewFile.jsp]
HSSFSheet cannot be resolved to a type
64: FileInputStream fs =new FileInputStream(filename);
65: HSSFWorkbook wb = new HSSFWorkbook (fs);
66: for(int k = 0; k < wb.getNumberOfSheets(); k++){
67: HSSFSheet sheet = wb.getSheetAt(k);
68: int rows = sheet.getPhysicalNumberOfRows();
69: DataFormatter formatter = new DataFormatter();
70:
An error occurred at line: [69] in the jsp file: [/NewFile.jsp]
DataFormatter cannot be resolved to a type
66: for(int k = 0; k < wb.getNumberOfSheets(); k++){
67: HSSFSheet sheet = wb.getSheetAt(k);
68: int rows = sheet.getPhysicalNumberOfRows();
69: DataFormatter formatter = new DataFormatter();
70:
71: for(int r = 0; r < rows; r++){
72: HSSFRow row = sheet.getRow(r);
An error occurred at line: [69] in the jsp file: [/NewFile.jsp]
DataFormatter cannot be resolved to a type
66: for(int k = 0; k < wb.getNumberOfSheets(); k++){
67: HSSFSheet sheet = wb.getSheetAt(k);
68: int rows = sheet.getPhysicalNumberOfRows();
69: DataFormatter formatter = new DataFormatter();
70:
71: for(int r = 0; r < rows; r++){
72: HSSFRow row = sheet.getRow(r);
An error occurred at line: [72] in the jsp file: [/NewFile.jsp]
HSSFRow cannot be resolved to a type
69: DataFormatter formatter = new DataFormatter();
70:
71: for(int r = 0; r < rows; r++){
72: HSSFRow row = sheet.getRow(r);
73: int cells = row.getPhysicalNumberOfCells();
74: %><tr><%
75: for(int n=0;n<cells;n++){
堆栈跟踪如下所示。
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:212)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:379)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:601)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
如果我为此编写一个java程序并将相同的JAR添加到我的项目结构中,它运行正常。可能是什么问题?
我试着在网上搜索。一种解决方案是重启服务器,但没有用。另一个是检查是否包含了JAR,完成了。
答案 0 :(得分:0)
mybe you can try to open %TOMCAT_HOME%conf\server.xml and add context
for example:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="access address" docBase="your project path" reloadable="true">
</Context>
</Host>