Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

java - 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)

Okay, I'm trying to import a Java class into my JSP file, but Tomcat gives me the error:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [16] in the generated java file: [I:pathoindex_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"));

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

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.

Help, please!

(And don't chastise me for using scriptlets, I'm trying to clean them up!)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Maybe it had something to do with restarting Tomcat? Well, it works now, anyway.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...