【问题标题】:Getting error message "Only a type can be imported..." when trying to execute jsp page尝试执行 jsp 页面时收到错误消息“只能导入类型...”
【发布时间】:2011-02-07 17:30:27
【问题描述】:

我有一个试图引用一些用户定义的类的 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:

所以我把import语句改成这样:

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

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

【问题讨论】:

  • 如果您使用 OSGI 和 Felix,请确保您的包已启动并且是否已导出所有需要的包。

标签: java jsp


【解决方案1】:

路径

/var/lib/tomcat6/webapps/examples/jsp/JSPEssbase2/WebContent/WEB-INF/classes/pikefin

应该是

/var/lib/tomcat6/webapps/examples/WEB-INF/classes/pikefin

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

【讨论】:

    【解决方案2】:

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

    其余的都是正确的,只要把这些jar文件放在WEB-INF/lib里面就可以顺利导入了。

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 这个JSP编译错误其实有点误导。它在 NoClassDefFoundError 的封面下。
      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-03
        • 2012-01-21
        • 2021-10-11
        • 2021-06-13
        相关资源
        最近更新 更多