GeeCON Prague 2014*
The moose likes Servlets and the fly likes classpath or package problems? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "classpath or package problems?" Watch "classpath or package problems?" New topic
Author

classpath or package problems?

darine darine
Ranch Hand

Joined: Mar 08, 2001
Posts: 43
Hi
what the settings of classpath with tomcat3.1 to access classes
directory?is it by default or what?
I have my files in the bottom of this message.
When i append the package name to the class name i do not need to import the package using the page directive. it works fine.
I've tried to put the bean java file in the beans directory under classes directory without "package beans;" statement and I've tried to run my jsp file,I still get the message can't load the bean class.
here my jsp file:
//=================
<%@ page import="beans.*" %>
<jsp:useBean id="stringBean" class="StringBean" />
<%-- <jsp:getProperty name="stringBean" property="message" /> --%
<jsp:setProperty name="stringBean" property="message" value="hello matt from new directories " />
<jsp:getProperty name="stringBean" property="message" /><br>
//===========================
Here is my bean java file:
//==========================
public class StringBean
{
private String message="No message specified ";
public void setMessage(String message)
{
this.message=message;
}
public String getMessage()
{
return this.message;
}
}
Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
Try finding out from the compiled jsp's .java code. It could be problem with the package definition rather than classpath.
darine darine
Ranch Hand

Joined: Mar 08, 2001
Posts: 43
Thanks for your reply.
How and where do we can check out the jsp's java code?
however i've checked almost everyword and i've changed even the bean and the jsp file too,i still getting the same message that says can't load the class stringBean.
thanks again.
darine darine
Ranch Hand

Joined: Mar 08, 2001
Posts: 43
Thanks for your reply.
How and where do we can check out the jsp's java code?
however i've checked almost everyword and i've changed even the bean and the jsp file too,i still getting the same message that says can't load the class stringBean.
thanks again.
paul sun
Greenhorn

Joined: Dec 22, 2000
Posts: 28
work directory
Try to do this:

//=================
<%@ page import="beans.*" %>
<jsp:useBean id="stringBean"
class="beans.StringBean" />
<%-- <jsp:getProperty name="stringBean" property="message" /> --%
<jsp:setProperty name="stringBean" property="message" value="hello matt from new directories " />
<jsp:getProperty name="stringBean" property="message" /><br>
//===========================
Here is my bean java file:
//==========================
package beans;
public class StringBean
{
private String message="No message specified ";
public void setMessage(String message)
{
this.message=message;
}
public String getMessage()
{
return this.message;
}
}

[This message has been edited by paul sun (edited March 09, 2001).]
darine darine
Ranch Hand

Joined: Mar 08, 2001
Posts: 43
Thnaks for your time,it works the way you said,but it works even without the page directive.
My question is if i do not put " package beans;" in my stringBean.java file,can i use that directive as above"<%@ page import="beans.*" %>
and the i use the action <jsp:useBean id="stringBean" class="stringBean" />
can i do that?
thanks for your time again.
paul sun
Greenhorn

Joined: Dec 22, 2000
Posts: 28
Either
"<%@ page import="beans.*" %>
<jsp:useBean id="stringBean" class="stringBean" />
or
<jsp:useBean id="stringBean" class="beans.stringBean" />
is ok.
But "package beans;" must appear in the "stringBean.java" file. If not, the compiled jsp (or servlet) can not find the "stringBean.class" via the class path search.
Compile "stringBean.java" without "package beans;" in the java file, and put the class file in the /web-inf/classes, and then use
<jsp:useBean id="stringBean" class="stringBean" /> without directive. See what you get.
Originally posted by darine darine:
Thnaks for your time,it works the way you said,but it works even without the page directive.
My question is if i do not put " package beans;" in my stringBean.java file,can i use that directive as above"<%@ page import="beans.*" %>
and the i use the action <jsp:useBean id="stringBean" class="stringBean" />
can i do that?
thanks for your time again.


[This message has been edited by paul sun (edited March 09, 2001).]
 
GeeCON Prague 2014
 
subject: classpath or package problems?