wood burning stoves*
The moose likes JSP and the fly likes Class not found errors for JSPs in sub-directories Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Class not found errors for JSPs in sub-directories" Watch "Class not found errors for JSPs in sub-directories" New topic
Author

Class not found errors for JSPs in sub-directories

Benny Andrews
Greenhorn

Joined: Nov 28, 2005
Posts: 3
Hello:

Main-Issue:
- I have some java-class files in the \<my-web-app>\web-inf\classes directory. These classes do not belong to any packages.
- I have some jsps in the \<my-web-app>\ directory and also in some sub-directories in the \<my-web-app>\ directory. Example: \<my-web-app>\test\index1.jsp.
- The jsps in the \<my-web-app>\ can invoke the classes in the \<my-web-app>\web-inf\classes directory with no issues. But, the jsps in the sub-directories CANNOT see the classes in the \<my-web-app>\web-inf\classes directory. I get a "class not found" error. (this is just in oc4j).

First of all, just a background to the issue:
- I am trying to port a web application from JRUN to OC4J.
- I want to do this with minimal changes to the existing code.
- The application has been running on JRUN for a while. I only see the above mentioned error (class not found) error when trying to run it on oc4j.
- As a test, I created my own test application to verify:
(-) I wrote a simple java class (test.class) with no package and placed it in the web-inf\classes directory
(-) I wrote a jsp file (index.jsp) to invoke test.class. I placed the jsp at the top-level directory of the web-app.
(-) I wrote another jsp file (index1.jsp) to invoke test.class as well. I placed that jsp file in a sub-directory in the top-level directory of the web-app.
(-) index.jsp worked without any problems. index1.jsp gave the "class not found" error.

(-) As another test, I then modified the class to be in a package (com.benny). I then changed the jsps to call "com.benny.test" rather than just "test". This time, both index.jsp and index1.jsp worked fine.

So, I guess my question is, do these classes have to be in a package? I am trying to avoid having to make a lot of changes to the app. If they do have to be in packages, then I have re-compile a lot of class files, add import statements to jsps, etc.

Any help/suggestion would be appreciated.

Thanks,
Benny
C Broussard
Greenhorn

Joined: Jun 18, 2004
Posts: 28
can you paste a little bit of the code so we can see what it's looks like?

i would think you should be able to access them through the jsp import directive.

www.binaryfrost.com
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

I have some java-class files in the \<my-web-app>\web-inf\classes directory. These classes do not belong to any packages.


That's a non-starter before even getting to anything else. All classes referenced must be in a package other than the default.

And, you do know it's WEB-INF, not web-inf, right? When posting, please try to be accurate to these kinds of details.
[ November 28, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Benny Andrews
Greenhorn

Joined: Nov 28, 2005
Posts: 3
Hello:

The example j2ee application that I created to test is really simple.

Here is my directory structure:
\benny_test\web-inf\classes\test.class
\benny_test\web-inf\web.xml
\benny_test\index.jsp
\benny_test\test\index1.jsp

***************************************************************************

Here is the contents of the test.class file:
public class test
{
private String t = null;

public test(String t1)
{
setTest(t1);
}

public void setTest(String t1)
{
t = t1;
}

public String getTest()
{
return t;
}
}

***************************************************************************

Here is the contents of the index.jsp file:
<b> hello </b> <br />

<%
String test_str = null;
test ts = new test("Hello from the main jsp directory");
test_str = ts.getTest();
%>

<b> test_str is: </b> <%=test_str%>

<br /><br />

Click <a href="test/index1.jsp"> here </a> to test your jsp index1.jsp file in the test sub-directory

***************************************************************************

And, here is the contents of the test/index1.jsp file:

<b> hello from test sub-directory </b> <br />

<%
String test_str = null;
test ts = new test("Hello from the jsp test sub-directory");
test_str = ts.getTest();
%>

<b> test_str is: </b> <%=test_str%>
***************************************************************************

As you can see there are no import statements for test.class in the jsp pages.

index.jsp works fine.
test/index1.jsp gives me the following error:

Request URI:/benny_test/test/index1.jsp Exception: OracleJSP racle.jsp.provider.JspCompileException: Errors compiling:C:\OC4J\j2ee\home\application-deployments\default\benny_test\persistence\_pages\_test\_index1.java

[jsp src:line #:5] cannot resolve symbol symbol : class test location: class _test._index1 test ts = new test("Hello from the jsp test sub-directory");

[jsp src:line #:5] cannot resolve symbol symbol : class test location: class _test._index1 test ts = new test("Hello from the jsp test sub-directory");
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

You can move your classes into packages, or you can continue to have problems. Your choice.
Benny Andrews
Greenhorn

Joined: Nov 28, 2005
Posts: 3
Hello Bear:

Yes, sorry it is WEB-INF, not web-inf. I have it as WEB-INF.

Also, the application is working fine on JRUN. The classes can be seen even though they are not in packages and even though import statements are missing in the jsp files.

I get the "class not found" error when I try to run the application on OC4J.

I created a small j2ee application just for testing. I am seeing that the jsp's that are within sub-directories are not able to see the classes in the web-inf\classes directory, if the classes are not in packages and there are no import statements for those classes in the jsps. But the jsps that are at the top-level directory of the web-app are able to see those classes.

So, I'm wondering why the jsps in the top-level directory can see the classes, but the jsps in the sub-directories cannot.

Thanks,
Benny
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

So, I'm wondering why the jsps in the top-level directory can see the classes, but the jsps in the sub-directories cannot.


A fluke most likely. If you were to run the app in Tomcat, I'm willing to bet they'd all error.

If you want the app to work reliably, all the classes must be in non-default packages. This is a limitation of the JRE 1.4+ and class-loaders.
[ November 28, 2005: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class not found errors for JSPs in sub-directories