By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,739 Members | 2,014 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,739 IT Pros & Developers. It's quick & easy.

Class files for jsp

P: n/a
I am using Jserv on apache and I cannot instantiate from a class file in
JSP.
I was using servlets before and any class I put in the same directory (or
other directories indicated with a classpath in the Jservproperties file)
would work fine. But JSP files (which are in a different directory) cannot
seem to find my classes no matter where I put them...whether in a classpath
or not. I even put them in the WEB_INF/classes folder and still nothing.
I have searched everywhere for an answer. Does anyone know???

H.Ellis Ensle

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Harold Ensle wrote:
I am using Jserv on apache and I cannot instantiate from a class file in
JSP.
I was using servlets before and any class I put in the same directory (or
other directories indicated with a classpath in the Jservproperties file)
would work fine. But JSP files (which are in a different directory) cannot
seem to find my classes no matter where I put them...whether in a classpath
or not. I even put them in the WEB_INF/classes folder and still nothing.
I have searched everywhere for an answer. Does anyone know???

Harold,

Perhaps you should post some sample code and describe the directory
structure of your WAR. One question comes to mind however: did you
import the desired classes with <@page import="" @> ?

Ray

Jul 17 '05 #2

P: n/a

"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:Va*****************@twister.nyroc.rr.com...
Harold Ensle wrote:
I am using Jserv on apache and I cannot instantiate from a class file in
JSP.
I was using servlets before and any class I put in the same directory (or other directories indicated with a classpath in the Jservproperties file) would work fine. But JSP files (which are in a different directory) cannot seem to find my classes no matter where I put them...whether in a classpath or not. I even put them in the WEB_INF/classes folder and still nothing.
I have searched everywhere for an answer. Does anyone know???

Harold,

Perhaps you should post some sample code and describe the directory
structure of your WAR. One question comes to mind however: did you
import the desired classes with <@page import="" @> ?

Ray


Thank you for the reply. This seems to be part of the problem. So I now have
something
like:

<%@ page import="ZClass"%>
<%
ZClass zc=new ZClass(1);
%>

The class itself has:

public class ZClass
{
ZClass(int x)
{
......
}
}

Now the JSP is acting like it finds the class (no error on the import)
but it is saying there is no constructor of the type to be found.
But I see a constructor there. What did I do wrong?

(I think Java hates me.)

H.Ellis Ensle
Jul 17 '05 #3

P: n/a
Harold Ensle wrote:
"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:Va*****************@twister.nyroc.rr.com...
Harold Ensle wrote:
I am using Jserv on apache and I cannot instantiate from a class file in
JSP.
I was using servlets before and any class I put in the same directory
(or
other directories indicated with a classpath in the Jservproperties
file)
would work fine. But JSP files (which are in a different directory)
cannot
seem to find my classes no matter where I put them...whether in a
classpath
or not. I even put them in the WEB_INF/classes folder and still nothing.
I have searched everywhere for an answer. Does anyone know???


Harold,

Perhaps you should post some sample code and describe the directory
structure of your WAR. One question comes to mind however: did you
import the desired classes with <@page import="" @> ?

Ray

Thank you for the reply. This seems to be part of the problem. So I now have
something
like:

<%@ page import="ZClass"%>
<%
ZClass zc=new ZClass(1);
%>

The class itself has:

public class ZClass
{
ZClass(int x)
{
......
}
}

Now the JSP is acting like it finds the class (no error on the import)
but it is saying there is no constructor of the type to be found.
But I see a constructor there. What did I do wrong?

(I think Java hates me.)


I would wager that the issue is that you didn't declare the constructor
public, like so:

public class ZClass
{
public ZClass(int x)
{
......
}
}

Java defines four access levels: public, protected, private and package
or default. Package level is the default that is used when no access
specifier is, well, specified. (IMHO, it would have been better to make
an explicit keyword for package level and require one.) Public,
protected and private behave as one would expect from other OO
languages. Package level defines an access level within a package; any
class within the same package can access the method, variable, etc.
This provides functionality similar to C++ friends. Note that unless
the package is sealed, nothing prevents others from creating classes in
the same package and exploiting the access, if you care about that sort
of thing.

Another interesting thing is that the access levels in descending order
are public, protected, package and private. That means that protected
implies package. Which means that you cannot have methods, variables
etc that are visible to the subclass but not to the other members of the
package. (IMHO, I would have preferred public, package, protected and
private; or even something not well-ordered where package and protected
are unrelated.)

Ray


Jul 17 '05 #4

P: n/a

"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:F3******************@twister.nyroc.rr.com...
Harold Ensle wrote:
"Raymond DeCampo" <rd******@spam-I-am-not.twcny.rr.com> wrote in message
news:Va*****************@twister.nyroc.rr.com...
Harold Ensle wrote:

I am using Jserv on apache and I cannot instantiate from a class file inJSP.
I was using servlets before and any class I put in the same directory
(or
other directories indicated with a classpath in the Jservproperties


file)
would work fine. But JSP files (which are in a different directory)


cannot
seem to find my classes no matter where I put them...whether in a


classpath
or not. I even put them in the WEB_INF/classes folder and still nothing.I have searched everywhere for an answer. Does anyone know???
Harold,

Perhaps you should post some sample code and describe the directory
structure of your WAR. One question comes to mind however: did you
import the desired classes with <@page import="" @> ?

Ray

Thank you for the reply. This seems to be part of the problem. So I now have something
like:

<%@ page import="ZClass"%>
<%
ZClass zc=new ZClass(1);
%>

The class itself has:

public class ZClass
{
ZClass(int x)
{
......
}
}

Now the JSP is acting like it finds the class (no error on the import)
but it is saying there is no constructor of the type to be found.
But I see a constructor there. What did I do wrong?

(I think Java hates me.)


I would wager that the issue is that you didn't declare the constructor
public, like so:

public class ZClass
{
public ZClass(int x)
{
......
}
}

Java defines four access levels: public, protected, private and package
or default. Package level is the default that is used when no access
specifier is, well, specified. (IMHO, it would have been better to make
an explicit keyword for package level and require one.) Public,
protected and private behave as one would expect from other OO
languages. Package level defines an access level within a package; any
class within the same package can access the method, variable, etc.
This provides functionality similar to C++ friends. Note that unless
the package is sealed, nothing prevents others from creating classes in
the same package and exploiting the access, if you care about that sort
of thing.

Another interesting thing is that the access levels in descending order
are public, protected, package and private. That means that protected
implies package. Which means that you cannot have methods, variables
etc that are visible to the subclass but not to the other members of the
package. (IMHO, I would have preferred public, package, protected and
private; or even something not well-ordered where package and protected
are unrelated.)

Ray


Thanks. This was very informative. Using public worked. However, when
I used the class from a compiled servlet, it worked without "public" and
that
is why I didn't think it was needed. Apparently the compiler had public as
the default.

H.Ellis Ensle

Jul 17 '05 #5

P: n/a
Harold Ensle wrote:


Thanks. This was very informative. Using public worked. However, when
I used the class from a compiled servlet, it worked without "public" and
that
is why I didn't think it was needed. Apparently the compiler had public as
the default.


It is unlikely that the compiler "had public as the default." That
would violate the Java Language specification. More likely was that the
servlet was in the same package as the other class. (Probably both were
in the "default" package that classes without a package directive are
placed in.) That would give it access to anything declared without an
explicit access modifier.

Ray

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.