java 尝试执行jsp页面时收到错误消息“只能导入一种类型...”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4924412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting error message "Only a type can be imported..." when trying to execute jsp page
提问by opike
I have a jsp page that is trying to reference some user defined classes. These classes were compiled with the line:
我有一个试图引用一些用户定义类的 jsp 页面。这些类是用以下行编译的:
package pikefin;
and place in the directory:
并放置在目录中:
/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin
/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin
Here is my jsp code:
这是我的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>
This is the full error message:
这是完整的错误消息:
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
Update 1:
更新 1:
So I changed the import statement to this:
所以我把import语句改成这样:
<%@ page import="pikefin.*" %>
<%@ page import="pikefin.*" %>
And created a new directory structure that looks like this:
并创建了一个新的目录结构,如下所示:
[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:
And now I get this error message:
现在我收到此错误消息:
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>
回答by BalusC
The path
路径
/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin
/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin
should have been
本来应该
/var/lib/tomcat6/webapps/examples/WEB-INF/classes/pikefin
/var/lib/tomcat6/webapps/examples/WEB-INF/classes/pikefin
The WEB-INF
has to go directly in the webapp project folder.
在WEB-INF
有直接在Web应用程序项目文件夹中去。
回答by theshadow
As an additional note, some classes are packaged in jar files that act as zip files, and thus must be extracted or they will not be found. It happened to me with chemistry-opencmis-osgi-client-0.7.0.jar
. In this case, the jsp could not locate the necessary imports, and it was because inside the jar file there was in turn a subdirectory called lib that contained the actual jars that I required. IMO it should have been better if these were packaged as zip or tar.gz instead of jar causing my confusion.
作为附加说明,某些类被打包在充当 zip 文件的 jar 文件中,因此必须解压缩,否则将找不到它们。它发生在我身上chemistry-opencmis-osgi-client-0.7.0.jar
。在这种情况下,jsp 无法找到必要的导入,这是因为在 jar 文件中,有一个名为 lib 的子目录,其中包含我需要的实际 jar。IMO 如果将它们打包为 zip 或 tar.gz 而不是 jar 会更好,这会导致我的困惑。
The rest is correct, as long as these jar files are put in WEB-INF/lib
inside they will be imported without trouble.
剩下的就对了,只要把这些jar文件放进WEB-INF/lib
去就可以顺利导入了。
回答by josh.trow
You need to set it as pikefin.PopulateSpreadsheet.* or similar, as you have it the error is correct.
你需要将它设置为 pikefin.PopulateSpreadsheet.* 或类似的,因为你有它错误是正确的。
Only a type can be imported. pikefin.PopulateSpreadsheet resolves to a package
回答by sethi.anuj
I was using eclipse for my project and faced the same issue. I solved this problem by changing the output folder for my java code to "...\WEB-INF\classes"
.
我在我的项目中使用 eclipse 并面临同样的问题。我通过将 java 代码的输出文件夹更改为"...\WEB-INF\classes"
.