I get the error: "Only a type can be imported. XYZ resolves to a package."
Someone has explained the cause here but I am not sure what I supposed to do to fix this. FYI: I am using Eclipse. I have added the code that does the importing below. The java.util.* import works fine.
<%@ page import="java.util.*"%> <%@ page import="org.eresearch.knowledgeportal.model.Category"%> <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao"%> <% CategoryDao catDao = new CategoryDao(); ArrayList<Category> catList = catDao.selectCategory(); // %>
Edit: the actual error is below:
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in the generated java file Only a type can be imported. org.eresearch.knowledgeportal.model.Category resolves to a package
Well, you are not really providing enough details on your webapp but my guess is that you have a JSP with something like that:
<%@ page import="java.util.*,x.y.Z"%>
And x.y.Z
can't be found on the classpath (i.e. is not present under WEB-INF/classes
nor in a JAR of WEB-INF/lib
).
Double check that the WAR you deploy on Tomcat has the following structure:
my-webapp |-- META-INF | `-- MANIFEST.MF |-- WEB-INF | |-- classes | | |-- x | | | `-- y | | | `-- Z.class | | `-- another | | `-- packagename | | `-- AnotherClass.class | |-- lib | | |-- ajar.jar | | |-- bjar.jar | | `-- zjar.jar | `-- web.xml |-- a.jsp |-- b.jsp `-- index.jsp
Or that the JAR that bundles x.y.Z.class
is present under WEB-INF/lib
.
OK I just solved it. In the last import I added a ";" by copying other code examples. I guess it's the standard line ending that is required.
So
<%@ page import="java.util.*" %> <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao" %> <%@ page import="org.eresearch.knowledgeportal.model.Category" %>
became
<%@ page import="java.util.*" %> <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao" %> <%@ page import="org.eresearch.knowledgeportal.model.Category;" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With