尝试执行jsp页面时收到错误消息“只能导入类型...”

时间:2011-02-07 17:30:27

标签: java jsp

我有一个jsp页面试图引用一些用户定义的类。这些类是用以下行编译的:

package pikefin;

并放在目录中:

的/ var / lib中/ tomcat6中/ web应用/实施例/ JSP / JSPEssbase2 /的WebContent / WEB-INF /类/ 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:

所以我将import语句更改为:

&lt;%@ page import =“pikefin。*”%&gt;

并创建了一个新的目录结构,如下所示:

[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>

4 个答案:

答案 0 :(得分:3)

路径

  

的/ var / lib中/ tomcat6中/ web应用/实施例/ JSP / JSPEssbase2 /的WebContent / WEB-INF /类/ pikefin

应该是

  

的/ var / lib中/ tomcat6中/ web应用/实施例/ WEB-INF /类/ pikefin

WEB-INF必须直接进入webapp项目文件夹。

答案 1 :(得分:1)

作为补充说明,某些类打包在充当zip文件的jar文件中,因此必须提取或找不到它们。 chemistry-opencmis-osgi-client-0.7.0.jar发生在我身上。在这种情况下,jsp无法找到必要的导入,这是因为在jar文件中又有一个名为lib的子目录,其中包含我需要的实际jar。 IMO本来应该更好,如果这些包装为zip或tar.gz而不是jar导致我的混乱。

其余的都是正确的,只要这些jar文件放在WEB-INF/lib内,就可以毫无困难地导入它们。

答案 2 :(得分:0)

你需要将它设置为pikefin.PopulateSpreadsheet。*或类似的,因为你有错误是正确的。

Only a type can be imported. pikefin.PopulateSpreadsheet resolves to a package

答案 3 :(得分:0)

我在项目中使用eclipse并面临同样的问题。我通过将我的java代码的输出文件夹更改为"...\WEB-INF\classes"来解决了这个问题。