只能导入一种类型。 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\to\index_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.
请帮助!
(并且不要惩罚我使用scriptlet,我是试图清理它们!)
(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屋!