【发布时间】:2017-01-17 20:18:14
【问题描述】:
我有一个主要的jsp 文件,它使用boxers 包中的java 类。但是当我尝试运行jsp 时,出现以下错误:
HTTP Status 500 - Unable to compile class for JSP:in the jsp file: /web/date_info.jsp boxers.B cannot be resolved to a type.
date_info.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<p><%= boxers.B.voice()%></p>
</body>
</html>
B类:
package boxers;
public class B {
public static String voice()
{
return "HELLO";
}
}
我已阅读版本之间的冲突可能导致此问题;我的 Java 版本是 8,Tomcat 8.5..
我查看了webapps/my_app/build/web/WEB-INF/classes/boxers 文件夹,其中有一个B.class 文件...
编辑:我想知道那些投反对票的人是否至少知道问题的答案。
【问题讨论】:
-
尝试在你的jsp页面中导入包
boxers,比如<%@ page import="boxers" %>,然后你可以在不指定包的情况下访问类 -
boxers.B cannot be resolved to a type就像 searchnig 搜索一个名为boxers的类,其中包含一个名为 B 的属性 -
@El Sam 我不能只导入拳击手 - netbeans 需要 '.'。导入
<%@ page import="boxers.*" %>并使用B.voice()不会改变事情..B cannot be resolved -
好的,导入B类
<%@ page import="boxers.B" %>然后就可以直接调用voice()了 -
@El Sam Netbeans 突出显示它 - 如果没有
B或boxers.B在它之前找不到方法..