只能导入一个类型.ABC 解析为一个包 [英] Only a type can be imported. ABC resolves to a package
问题描述
(我已经阅读了关于这个主题的其他问题,但没有一个有帮助)
(I've read other questions on this topic, but none of them have helped)
好的,我正在尝试将 Java 类导入到我的 JSP 文件中,但是 Tomcat 给了我错误:
Okay, I'm trying to import a Java class into my JSP file, but Tomcat gives me the error:
org.apache.jasper.JasperException:无法为 JSP 编译类:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [16] in the generated java file: [I:path oindex_jsp.java]
Only a type can be imported. org.runas.XKCDUtils resolves to a package
An error occurred at line: 7 in the jsp file: /index.jsp
XKCDUtils cannot be resolved
4: String data = null;
5: int finalComic = 1;
6: int comicNo = 1;
7: finalComic = XKCDUtils.getFinalComic();
8:
9: if (request.getParameter("page") != null)
10: comicNo = Integer.parseInt(request.getParameter("page"));
我的JSP文件中的import语句是:
The import statement in my JSP file is:
<%@page import="java.io.*, java.net.*, org.runas.XKCDUtils" %>
我的目录结构的相关部分是:
The relevant section of my directory structure is:
webapps
`-ROOT
`-index.jsp
|-WEB-INF
`-web.xml
|-classes
`-org
`-runas
`-XKCDUtils.class
我很困惑,因为 org.runas.XKCDUtils 解析为一个包
,但它显然是一个类文件,在我认为是正确的目录中.
I'm confused because org.runas.XKCDUtils resolves to a package
, and yet it is clearly a class file, in what I believe is the correct directory.
请帮忙!
(不要因为我使用脚本而责备我,我正在努力清理它们!)
(And don't chastise me for using scriptlets, I'm trying to clean them up!)
推荐答案
好吧,这很奇怪.我把导入分成三个导入,
Okay, this is weird. I split the import into three imports,
<%@page import="java.io.*" %>
<%@page import="java.net.*" %>
<%@page import="org.runas.XKCDUtils" %>
它神奇地决定工作.然后当我把导入改回来时,
and it magically decided to work. Then when I changed the imports back,
<%@page import="java.io.*, java.net.*, org.runas.XKCDUtils" %>
它神奇地决定继续工作.
it magically decided to keep working.
也许和重启Tomcat有关?好吧,无论如何它现在都有效.
Maybe it had something to do with restarting Tomcat? Well, it works now, anyway.
这篇关于只能导入一个类型.ABC 解析为一个包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!