Reputation: 73
I have a .java
file containing a public
class. It is located under the 'web pages' folder (not under web-inf folder).
On my jsp page I have imported it as: <%@ page import="packagename.javafilename;" %>
When I run jsp file, I get error as:
Unable to compile class for jsp.
Only a type can be imported. Packagename.filename resolves to a package
Upvotes: 0
Views: 5830
Reputation: 10987
From your question things are not very clear.
First of all jsp cannot access .java but a .class file i.e. you have to keep your code compiled.
Secondly the class should be in the WEB-INF/classes folder or a jar in WEB-INF/lib folder.
Upvotes: 1
Reputation: 448
Use this syntax:
<%@ page import="package.filename" %>
In the last import, you might need to add a semicolon after the end of the package.filename. So, if you have like 3 imports, then in the 3rd import line make sure to put a semicolon as:
<%@ page import="package.filename;" %>
One more thing, make sure that the class files are in WEB-INF/classes folder.
Upvotes: 0
Reputation: 68715
As mentioned in the comments there seems to be a missing % towards the end. Here is the way to import classes in jsp
// To import one class
<%@ page import="com.xyz.MyClass" %>
OR
// To import multiple classes from the com.xyz package
<%@ page import="com.xyz.*" %>
Upvotes: 2