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
.javafiles? Some places told me to put them in/srcand 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 insrcor 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
.classfiles and not.javafiles. Use thejavaccommand to compile files - here's more information. - If you get the
resolves to a packageerror ensure that the files are in the right place, for example if you haveCclass in packagea.byou need theC.classfile to be inWEB-INF/classes/a/b/C.class. If it is, try simply restarting your IDE/server.