0

How to import Java class inside JSP file? <%@page import="javaname.java"%> is not working in Eclipse Neon. Already defined full path still not working.

We have an existing project that the java class is inside of WEB-INF/classes instead of src folder but when we try to do it on another project, we cannot import anymore using the same syntax (<%@ page import="package.javaclass"%>)

Java class:

enter image description here

JSP:

enter image description here

Marilou Maala
  • 31
  • 1
  • 1
  • 6

3 Answers3

1

Maybe it should be:

<%@page import="package.nameOfTheYouClass"%>

You don't need to add the .java ending to the class name.

Nurjan
  • 5,889
  • 5
  • 34
  • 54
1

The Totp.java source file doesn't belong in the WEB-INF/classes folder, it belongs in the fa folder under src so that Eclipse will compile it for you. At runtime the server is supposed to find the compiled Totp.class file there. I'm guessing that Totp.java is not actually in the source folder, meaning this was a correct error message all along.

If you've been adding files to, and directly editing files in, the WEB-INF/classes folder, you're doing it wrong. That folder is only ever supposed to hold classes compiled from the source folders like src and other resources copied there, by Eclipse, from the source folders.

nitind
  • 19,089
  • 4
  • 34
  • 43
  • I know that the java file should be in the scr folder. But when I placed the java file together with the wsdl files inside the src folder, it seems like they didn't connect to each other. So I decided to move it – Marilou Maala Dec 15 '16 at 01:10
  • Try putting it back to get past this problem, then open a separate question about that *original* one. – nitind Dec 15 '16 at 05:06
  • We have an existing project that the java class is inside of WEB-INF/classes instead of src folder but when we try to do it on another project, we cannot import anymore using the same syntax (<%@ page import="package.javaclass"%>) – Marilou Maala Jan 03 '17 at 05:25
  • When you say "java class", do you mean an actual compiled `.class` file this time? – nitind Jan 04 '17 at 06:20
  • Yes is the answer to your inquiry – Marilou Maala Jan 05 '17 at 07:44
  • That should probably go into a Class Folder (like a Source Folder, but for .class files), since the WEB-INF/classes folder is only used for final deployment, its contents ignored during development and validation. – nitind Jan 05 '17 at 08:17
-1

check if the name of your class is right and that's it.

Salah
  • 513
  • 7
  • 18