views:

389

answers:

4

Hi,

Its been a while since I had to do some Java/Jsp...

I have a java class in WEB-INF/classes/MyClass.java The build in Netbeans is successful and I can see MyClass.class in the classes folder.

In my jsp page, I've got <%@ page import="MyClass" %>

Tomcat says that the import cannot be resolved...

I tried to put MyClass in a package(WEB-INF/com/MyClass) and then import the package into my Jsp file. The import doesnt throw an error anymore then, but I cannot instanciate a MyClass object, says the type is unresolved...

What am I doing wrong here..?

All help appreciated! :)

+3  A: 
WEB-INF/classes/MyClass.java

makes me guess that you're using the default package which is'nt a good practice at all. Try assigning your class to a package and do the import according to that.

Do something like:

package myPackage;

class myClass
{
...
}

And afterwards:

<%@ page import="myPackage.myClass" %>
KB22
A: 

What package is MyClass in? If the default package then you can put the class file in

WEB-INF/classes

if it's in a package, then use the package directory hierarchy under classes

djna
A: 

.class file must be placed inside the classes folder under WEB-INF. So, the location of MyClass.class must be WEB-INF/classes/com/ (In case com is a package).

<%
 // Instantiate a MyClass

 com.MyClass obj=new com.MyClass();

%>

OR

<%@ page import="com.MyClass" %>
<%
   MyClass obj=new MyClass();
%>
adatapost
A: 

OMG, I found my mistake...

Netbeans wasn't copying the lib files to the right folder, my jsp page was being updated, so it looked like all the files were copied, but actually MyClass.class wasnt in the folder...

Thanks for your help!

Piero
yep. Netbeans keeps classes inside build folder. If u r using netbeans, i suggest you to get a war from it and unpack the war using tomcat(on restart tomcat automatically unpacks if that option is set to true). Then you need not worry about copying class files.
tony_le_montana
Yep that's what I'm doing now, using a war and everything works perfect!Thanks all for your help
Piero