views:

66

answers:

0

Hello,

I am trying to access a class I wrote using JavaScript's Packages object, but I get a ClassNotFoundException. I am running Apache Tomcat 6, using Firefox 3.0.11 to view the content.

Here is the class:

package tests;
public class testclass {
    public String str;
    public testclass() {
        str = "String from external class\n";
    }
    public String getString() {
        return str;
    }
}

Here is the html/JavaScript:

<script type="text/javascript">  
var c = new Packages.tests.testclass();
var s2 = c.getString();
document.write(s2);
</script>

I have tried placing the testclass.class file in two different places:
webapps/MY_PROJECT/WEB-INF/classes/tests/testclass.class

and also in
webapps//MY_PROJECT/tests/testclass.class
as someone pointed out that Tomcat restricts access to the WEB-INF directory.

The same thing happens in both cases - ClassNotFoundException. The .jsp file that tries to access the java class is in webapps/MY_PROJECT directory.

Thank you