• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

index.jsp Error 300: Class XYZ not found

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I have created the following class (pretty simple)
public class Test {
public Test() {
}
public String metodo(){
return "OK...!";
}
}

But When I try to invoke the method from my JSP page I get this:
index.jsp Error 300: Class Text not found in class xyz.class.

It seems like I do not have access to my WEB-INF/classes directory.
Please advice.

Here you have my JSP Page.

<html>
<head>
<title>
index
</title>
<%! Text x = new Test();%>
</head>
<body bgcolor="#ffffff">
<form method="post">
<br><br>

>>>> <%= x.metodo() %>

<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
</form></body></html>



THANKS!
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jose Ortuno:

<%! Text x = new Test();%>



can you tell about Text ? shouldn't it be
Test x = new Test();

or there is also a class called Text ?
 
Jose Ortuno
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UPS..!

Sorry...
It should be :
<%! Test x = new Test(); %>
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some helpful suggestions:

1) Be careful when entering example code. Careless mistakes wastes people's time. People are unlikely going to want to spend their own time to help you if you're unwilling to spend some time yourself to proof-read your posts.

2) Use the UBB code tags (see the CODE button on the entry page) to preserve the formatting of your posted code.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With regards to your original question, I see no import statement in your JSP. Is there one for the class in question?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, if you're using j2sdk1.4.1 or higher, you'll need to package your classes.
 
Jose Ortuno
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, for writing guys,


I know that class packing is a good aproach. but:
Is it mandatory ind JDK 1.4 and Tomcat to do so?
I would like to know how Tomcat resolve the classpath since compiled JSPs classes are kept out of my default package( suppose I do not what to add my classes to any package).

Thanks,
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's less of a Tomcat issue than a Java issue.

Starting with j2sdk1.4.1, you can't import a non-packaged class from a packaged one. This was never allowed in the Java Specs but was working in older SDKs. They consider it a "closing of a loophole".

So, in short, a non-packaged bean is no longer just evidence of bad practices -- it's a bug.
[ April 29, 2005: Message edited by: Ben Souther ]
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is it mandatory ind JDK 1.4 and Tomcat to do so?



Did you read my answer to this very same question that you posted yesterday?

suppose I do not what to add my classes to any package



Then it won't work.
 
Jose Ortuno
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand this:

...you can't import a non-packaged class from a packaged one.


But I am not adding my Test class to any package and when I try to acces it within my JSP I get the runtime error from Tomcat. Moreover, it compiles.


Inregards to your comment Bear:

I did not notice somebody change my topic description so I did not read your post.
And I apologize for the topic description I used. I meant to post a Reply not a NEW TOPIC, may be I clicke the grong button, that's why named it "By the way..."

Thanks all you guys.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jasper generates servlet code from your JSPs.
The servlets generated go into the org.apache.jsp package.
You can see this code under TOMCAT_HOME/work.
Your JSP can not find the file because you didn't import it.
When you add the following imput line to the top of your JSP:
<%@ page import="Text" %>
You will probably get another error, either during compilation or at runtime.
This will be due to the fact the the generated servlet class (which is packaged) will be trying to import a non-packaged class.

If you package the Text class and put it under:
WEB-INF/classes/{package-name}/Text.class
and then change the import directive:
<%@ page import="{package-name}/Text" %>
your JSP will be able to find the class.
[ April 29, 2005: Message edited by: Ben Souther ]
 
Jose Ortuno
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
**** Now It makes a lot of sense ! ****.

Thanks a lot .... you guys are awesome !


 
reply
    Bookmark Topic Watch Topic
  • New Topic