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:
- Where should I place my
.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. - How can I import them correctly? I'm trying
<%@ page import = "packagename.name.*" %>
and it doesn't work in both cases above (when the package is insrc
or inclasses
.
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:
- As @user7294900 mentioned, you can only import
.class
files and not.java
files. Use thejavac
command to compile files - here's more information. - If you get the
resolves to a package
error ensure that the files are in the right place, for example if you haveC
class in packagea.b
you need theC.class
file to be inWEB-INF/classes/a/b/C.class
. If it is, try simply restarting your IDE/server.