Marilou Maala
Marilou Maala

Reputation: 31

Importing Java Class inside JSP file

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

Upvotes: 0

Views: 11200

Answers (3)

Salah
Salah

Reputation: 622

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

Upvotes: -1

nitind
nitind

Reputation: 20033

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.

Upvotes: 1

Nurjan
Nurjan

Reputation: 6073

Maybe it should be:

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

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

Upvotes: 1

Related Questions