For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > February 2005 > Java Beans & Packages









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Java Beans & Packages
Nick Havard

2005-02-02, 3:59 pm

Hi

Do Java beans need to be in their own packages?

I have a bean, which I put into a package containing servlets for my web
site. When I deploy to Apache/Tomcat, I get the following error from the
page accessing the bean. I'm using Oracle JDeveloper for writing the code
and it works fine in that.
============================
SEVERE: Servlet.service() for servlet displayPage threw exception
org.apache.jasper.JasperException: /users/signup.jsp(2,0) The value for the
useBean class attribute emPkg.EmUser is invalid.
at
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
at
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
at
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
at
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1223)
at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
============================

When I isolated the exact same bean code into a new package, the page worked
with no problems, and the bean behaved as expected.

I've done some searching on the internet and lots of people seem to have had
similar issues. In fact thats where I got the idea to isolate the bean into
a new package.

Any thoughts on what the problem could be. Thanks for your help.

Regards

Nick
news@nickhavardxyz.com

P.S. Remove xyz to reply


John C. Bollinger

2005-02-02, 8:59 pm

Nick Havard wrote:

> Do Java beans need to be in their own packages?


Bean classes, like any other Java classes, ought to be assigned to named
packages. They do not need packages all to themselves, however.

> I have a bean, which I put into a package containing servlets for my web
> site. When I deploy to Apache/Tomcat, I get the following error from the
> page accessing the bean. I'm using Oracle JDeveloper for writing the code
> and it works fine in that.
> ============================
> SEVERE: Servlet.service() for servlet displayPage threw exception
> org.apache.jasper.JasperException: /users/signup.jsp(2,0) The value for the
> useBean class attribute emPkg.EmUser is invalid.
> at
> org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
> at
> org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
> at
> org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
> at
> org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1223)
> at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
> at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
> at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
> at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
> at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
> at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
> ============================
>
> When I isolated the exact same bean code into a new package, the page worked
> with no problems, and the bean behaved as expected.
>
> I've done some searching on the internet and lots of people seem to have had
> similar issues. In fact thats where I got the idea to isolate the bean into
> a new package.


People frequently have problems when they attempt to use a bean whose
class is in a default (unnamed) package. This typically does not work.
You seem to be describing a different problem, however. Some possible
causes:

(1) You misspelled the class attribute of the relevant useBean action at
first, and when you moved the class and hence changed the useBean
invocation you fixed it without recognizing the real problem.

(2) The bean class is not packaged together with the other classes of
the package to which it is assigned. This could be trouble because
(a) It might fool a (slightly buggy) classloader into thinking the
class wasn't there at all.
(b) A classloader might very appropriately refuse to recognize the
bean class in this situation if the package to which it has putatively
been assigned is sealed.

There might be other explanations as well.

--
John Bollinger
jobollin@indiana.edu
Nick Havard

2005-02-05, 8:57 am

"John C. Bollinger" <jobollin@indiana.edu> wrote in message
news:ctrht6$4tg$1@rainier.uits.indiana.edu...
> Nick Havard wrote:
>
>
> Bean classes, like any other Java classes, ought to be assigned to named
> packages. They do not need packages all to themselves, however.
>
>
> People frequently have problems when they attempt to use a bean whose
> class is in a default (unnamed) package. This typically does not work.
> You seem to be describing a different problem, however. Some possible
> causes:
>
> (1) You misspelled the class attribute of the relevant useBean action at
> first, and when you moved the class and hence changed the useBean
> invocation you fixed it without recognizing the real problem.
>
> (2) The bean class is not packaged together with the other classes of the
> package to which it is assigned. This could be trouble because
> (a) It might fool a (slightly buggy) classloader into thinking the
> class wasn't there at all.
> (b) A classloader might very appropriately refuse to recognize the bean
> class in this situation if the package to which it has putatively been
> assigned is sealed.
>
> There might be other explanations as well.
>
> --
> John Bollinger
> jobollin@indiana.edu


Hi John,

Thanks for your reply.

I don't beleive my issue to be a spelling mistake since I copied the exact
code from the bean in one package to create new bean in a new package. Thus
the only difference was the package name. Also the original bean worked
within my JDeveloper development environment.

I don't understand yur second possibility with the bean not packagaed with
other classes. Could you elaborate a little. I'm a newbie to using
Java/JSP's/Servlets/Beans so please forgive me if I'm being a bit slow in
understanding.

Many thanks for your help.
--
Regards

Nick
news@nickhavardxyz.com

P.S. Remove xyz to reply


John C. Bollinger

2005-02-07, 4:01 pm

Nick Havard wrote:

> "John C. Bollinger" <jobollin@indiana.edu> wrote in message
> news:ctrht6$4tg$1@rainier.uits.indiana.edu...
>
>
>
> Hi John,
>
> Thanks for your reply.
>
> I don't beleive my issue to be a spelling mistake since I copied the exact
> code from the bean in one package to create new bean in a new package. Thus
> the only difference was the package name. Also the original bean worked
> within my JDeveloper development environment.


I was not describing a spelling mistake in the bean class, but rather in
the JSP that uses it. In any case, the package statement is exactly the
part of the class that has the potential to cause the kind of problem
you described if it were misspelled in the java source.

> I don't understand yur second possibility with the bean not packagaed with
> other classes. Could you elaborate a little. I'm a newbie to using
> Java/JSP's/Servlets/Beans so please forgive me if I'm being a bit slow in
> understanding.


You would normally put all the application-specific class files,
including those for all the beans, in exactly one of two places: in a
jar file in the webapp's WEB-INF/lib/ directory, or in a directory tree
rooted at WEB-INF/classes and mirroring the package structure. (It's
legal to use both, but it's likely to cause you trouble so don't.) If
you use jars, you put some of the classes for the bean's package in one
jar, and you put the bean class itself in a different jar then you might
possibly run into problem (2a). If you are working with a jar that
contains "sealed" packages then you cannot define new classes in any of
those packages (it's a jar / Java thing, not specific to JSP / servlets).

I am rather suspicious that your problem may fall into the category of
an inadvertent error that you fixed without realizing it when you
changed the bean's package. A simple spelling error was one possible
such problem, but there are others. Does the problem come back if you
change the bean package back (by hand, not by bringing back an old
version of the code)?


John Bollinger
jobollin@indiana.edu
Nick Havard

2005-02-08, 3:58 am

"John C. Bollinger" <jobollin@indiana.edu> wrote in message
news:cu7rsb$i43$1@rainier.uits.indiana.edu...
> Nick Havard wrote:
>
>
> I was not describing a spelling mistake in the bean class, but rather in
> the JSP that uses it. In any case, the package statement is exactly the
> part of the class that has the potential to cause the kind of problem you
> described if it were misspelled in the java source.
>
>
> You would normally put all the application-specific class files, including
> those for all the beans, in exactly one of two places: in a jar file in
> the webapp's WEB-INF/lib/ directory, or in a directory tree rooted at
> WEB-INF/classes and mirroring the package structure. (It's legal to use
> both, but it's likely to cause you trouble so don't.) If you use jars,
> you put some of the classes for the bean's package in one jar, and you put
> the bean class itself in a different jar then you might possibly run into
> problem (2a). If you are working with a jar that contains "sealed"
> packages then you cannot define new classes in any of those packages (it's
> a jar / Java thing, not specific to JSP / servlets).
>
> I am rather suspicious that your problem may fall into the category of an
> inadvertent error that you fixed without realizing it when you changed the
> bean's package. A simple spelling error was one possible such problem,
> but there are others. Does the problem come back if you change the bean
> package back (by hand, not by bringing back an old version of the code)?
>
>
> John Bollinger
> jobollin@indiana.edu


Hi John,

Yes, the problem comes back when I revert back to the original bean, or copy
all the code (except package statement) back to the original bean. I have
even tried deleting the class from the package and creating afresh.

Regards

Nick
news@nickhavardxyz.com

P.S. Remove xyz to reply


John C. Bollinger

2005-02-08, 3:58 am

Nick Havard wrote:
> Yes, the problem comes back when I revert back to the original bean, or copy
> all the code (except package statement) back to the original bean. I have
> even tried deleting the class from the package and creating afresh.


Then there is little more I (or anyone else) can do without seeing some
code. Whittle your code down to the minimum that exhibits the problem,
and post a compilable / deployable example.

--
John Bollinger
jobollin@indiana.edu
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com