java获取错误消息“只能导入类型…”尝试执行jsp页面时
我有一个jsp页面,试图引用一些用户定义的类。这些类使用以下行进行编译:
package pikefin;
并将其放入目录中:
/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin
以下是我的jsp代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="pikefin.PopulateSpreadsheet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
out.println(" Hello Oracle World5");
PopulateSpreadsheet tmp = new PopulateSpreadsheet();
out.println(" Hello Oracle World4"); %>
</body>
</html>
这是完整的错误消息:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
Only a type can be imported. pikefin.PopulateSpreadsheet resolves to a package
An error occurred at line: 13 in the jsp file: /jsp/JSPEssbase2/essbasedatasource.jsp
PopulateSpreadsheet cannot be resolved to a type
更新1:
因此,我将导入语句更改为:
<;%@page import=“pikefin.*”%>
并创建了一个新的目录结构,如下所示:
[ollie@devdataload jsp]$ ls -Rp JSPEssbase3/
JSPEssbase3/:
essbasedatasource.jsp META-INF/ WEB-INF/
JSPEssbase3/META-INF:
MANIFEST.MF
JSPEssbase3/WEB-INF:
classes/ lib/
JSPEssbase3/WEB-INF/classes:
pikefin/
JSPEssbase3/WEB-INF/classes/pikefin:
BatchSample$CellAddress.class Logs.class
BatchSample.class PopulateSpreadsheet.class
CustomBufferedWriter.class SkipLoadException.class
DBFunctions.class TestException.class
EssbaseConnect.class UtilityFunctions.class
JSPEssbase3/WEB-INF/lib:
现在我得到了这个错误消息:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 13 in the jsp file: /jsp/JSPEssbase3/essbasedatasource.jsp
PopulateSpreadsheet cannot be resolved to a type
10: <body>
11: <%
12: out.println(" Hello Oracle World5");
13: PopulateSpreadsheet tmp = new PopulateSpreadsheet();
14:
15: out.println(" Hello Oracle World4"); %>
16: </body>
# 1 楼答案
另外需要注意的是,有些类打包在充当zip文件的jar文件中,因此必须进行解压缩,否则将找不到它们。这件事发生在我身上
chemistry-opencmis-osgi-client-0.7.0.jar
。在本例中,jsp无法定位所需的导入,这是因为在jar文件中有一个名为lib的子目录,其中包含我所需的实际jar。依我看,如果把它们包装成拉链或焦油,效果会更好。gz而不是jar引起我的困惑其余部分是正确的,只要将这些jar文件放在
WEB-INF/lib
中,它们就可以顺利导入# 2 楼答案
路径
应该是
WEB-INF
必须直接进入webapp项目文件夹# 3 楼答案
您需要将其设置为pikefin。填写预表。*或者类似的,正如您所看到的,错误是正确的
# 4 楼答案
我在项目中使用eclipse时遇到了同样的问题。我通过将java代码的输出文件夹更改为
"...\WEB-INF\classes"
解决了这个问题