Reputation: 1475
I'm kind of a JSP noob (and I'm forced to write old school because of school) and I have this pure java file that I wrote. I want to use that FooBar.java
file and the class inside it (packagename.name.FooBar
) inside my .jsp
files. My questions are:
.java
files? Some places told me to put them in /src
and some told me to put them in /WebContent/WEB-INF/classes
. Both of these don't work.<%@ page import = "packagename.name.*" %>
and it doesn't work in both cases above (when the package is in src
or in classes
.EDIT: Now I've tried compiling them and putting them in WEB-INF/classes/packagename/name
, but I still get errors:
Only a type can be imported. packagename.name.FooBar resolves to a package
And then of course these (because it didn't import correctly): FooBar cannot be resolved to a type
.
What am I doing wrong?
EDIT: Thank you everyone! If you're wondering, here's what solved my problem:
.class
files and not .java
files. Use the javac
command to compile files - here's more information.resolves to a package
error ensure that the files are in the right place, for example if you have C
class in package a.b
you need the C.class
file to be in WEB-INF/classes/a/b/C.class
. If it is, try simply restarting your IDE/server.Upvotes: 1
Views: 745
Reputation: 58902
JSP file can import files with class extension and not java extension.
Class file is a compiled java file.
You need to compile you java file which will create FooBar.class
One option is to save FooBar.class file in a jar under /WEB-INF/lib
Second option is save FooBar.class inside your classes folder under relevant pack for example if your package is a.b /WEB-INF/classes/a/b/FooBar.class
Upvotes: 1