You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jeff Ousley <je...@yahoo.com> on 2003/01/13 23:37:44 UTC
how do I reference a bean that's inside my jsp page?
Hello,
I cannot seem to get this example below to work under
tomcat (I'm using version 4.1.18). I get an error
indicating that the class localBean cannot be found
such as:
java.lang.ClassNotFoundException: localBean
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1428)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1274)
....
I tried doing an import (which is now commented out)
to no avail. Can I not have a bean in my jsp page? If
I can, how do I reference it or what do I set so that
it can be found?
thanks!
example page
------------
<HTML>
<%-- <%@ page import="localBean" %> --%>
<%!
// this is a local "helper" bean for processing the
HTML form
static public class localBean
{
private String value;
public String getValue() { return value;}
public void setValue(String s) { value = s; }
}
%>
<jsp:useBean id="localBean" scope="page"
class="localBean" >
<%-- Every time we create the bean, initialize the
string --%>
<jsp:setProperty name="localBean" property="value"
value="World" />
</jsp:useBean>
<%-- Whatever HTTP parameters we have,
try to set an analogous bean property --%>
<jsp:setProperty name="localBean" property="*" />
<HEAD><TITLE>HelloWorld w/ JavaBean</TITLE></HEAD>
<BODY>
<CENTER>
<P><H1>Hello
<jsp:getProperty name='localBean'
property='value'/></H1></P>
<FORM method=post>
Enter a name to be greeted:
<INPUT TYPE="text" SIZE="32" NAME="value"
VALUE="<jsp:getProperty name='localBean'
property='value'/>">
<BR>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</CENTER>
</BODY>
</HTML>
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: how do I reference a bean that's inside my jsp page?
Posted by "Noel J. Bergman" <no...@devtech.com>.
> I cannot imagine how that would work in any app
> server. A Java bean is it's own class that can
> be used by ...
It works just fine in other JSP engines, e.g., GNUJSP. The example was just
a self-contained example for introducing bean tags, and the specific use is
limited to form handling where the bean is intended to have a 1:1
relationship with the HTML form. The documentation mentions that it is a
limited application (you *must* use page scope because the bean cannot be
used outside of that page, and any other scope would lead to classloader
problems).
--- Noel
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: how do I reference a bean that's inside my jsp page?
Posted by Charles Baker <ra...@yahoo.com>.
--- Jeff Ousley <je...@yahoo.com> wrote:
> Charles,
>
> The bean is actually on the same page in a
> declaration
> block. If I pull the bean out and put it into it's
> own
> class file, I can get it to work. I was just trying
> to
> get the example from the tutorial to work. It seems
> to
> work on the tutorial site, but I'm not sure what
> application server they are using.
>
> -jeff
{{SNIP}}
I cannot imagine how that would work in any app
server. A Java bean is it's own class that can be used
by a jsp, a servlet, or even a Java gui app. Strange.
What tutorial are you looking at?
=====
rascharles@yahoo.com
http://www.charleshbaker.com/~chb/
If you cannot in the long run tell everyone what you have been doing,
your doing was worthless. -- Edwim Schrodinger
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: how do I reference a bean that's inside my jsp page?
Posted by Jeff Ousley <je...@yahoo.com>.
Charles,
The bean is actually on the same page in a declaration
block. If I pull the bean out and put it into it's own
class file, I can get it to work. I was just trying to
get the example from the tutorial to work. It seems to
work on the tutorial site, but I'm not sure what
application server they are using.
-jeff
--- Charles Baker <ra...@yahoo.com> wrote:
>
> --- Jeff Ousley <je...@yahoo.com> wrote:
> > Hello,
> >
> > I cannot seem to get this example below to work
> > under
> > tomcat (I'm using version 4.1.18). I get an error
> > indicating that the class localBean cannot be
> found
> > such as:
> >
> >
> > java.lang.ClassNotFoundException: localBean
> > at
> >
>
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1428)
> > at
> >
>
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1274)
> > ....
> >
> >
> >
> > I tried doing an import (which is now commented
> out)
> > to no avail. Can I not have a bean in my jsp page?
> > If
> > I can, how do I reference it or what do I set so
> > that
> > it can be found?
> >
> > thanks!
> >
> >
> >
> > example page
> > ------------
> >
> > <HTML>
> > <%-- <%@ page import="localBean" %> --%>
> >
> > <%!
> > // this is a local "helper" bean for processing
> the
> > HTML form
> > static public class localBean
> > {
> > private String value;
> > public String getValue() { return
> value;}
> > public void setValue(String s) { value = s; }
> > }
> > %>
> >
> > <jsp:useBean id="localBean" scope="page"
> > class="localBean" >
>
> Where is the bean class file? Is it in
>
> $CATALINA_HOME/webapps/yourApp/WEB-INF/classes ?
>
> Is the bean in a package? If so, it needs to be in a
> corresponding directory structure under classes. Is
> you bean in fact named localBean.[java|class] ?
> Convention says Java classes should be named
> LocalBean.java.
>
> {{SNIP}}
>
> =====
> rascharles@yahoo.com
> http://www.charleshbaker.com/~chb/
> If you cannot in the long run tell everyone what you
> have been doing,
> your doing was worthless. -- Edwim Schrodinger
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up
> now.
> http://mailplus.yahoo.com
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: how do I reference a bean that's inside my jsp page?
Posted by Charles Baker <ra...@yahoo.com>.
--- Jeff Ousley <je...@yahoo.com> wrote:
> Hello,
>
> I cannot seem to get this example below to work
> under
> tomcat (I'm using version 4.1.18). I get an error
> indicating that the class localBean cannot be found
> such as:
>
>
> java.lang.ClassNotFoundException: localBean
> at
>
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1428)
> at
>
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1274)
> ....
>
>
>
> I tried doing an import (which is now commented out)
> to no avail. Can I not have a bean in my jsp page?
> If
> I can, how do I reference it or what do I set so
> that
> it can be found?
>
> thanks!
>
>
>
> example page
> ------------
>
> <HTML>
> <%-- <%@ page import="localBean" %> --%>
>
> <%!
> // this is a local "helper" bean for processing the
> HTML form
> static public class localBean
> {
> private String value;
> public String getValue() { return value;}
> public void setValue(String s) { value = s; }
> }
> %>
>
> <jsp:useBean id="localBean" scope="page"
> class="localBean" >
Where is the bean class file? Is it in
$CATALINA_HOME/webapps/yourApp/WEB-INF/classes ?
Is the bean in a package? If so, it needs to be in a
corresponding directory structure under classes. Is
you bean in fact named localBean.[java|class] ?
Convention says Java classes should be named
LocalBean.java.
{{SNIP}}
=====
rascharles@yahoo.com
http://www.charleshbaker.com/~chb/
If you cannot in the long run tell everyone what you have been doing,
your doing was worthless. -- Edwim Schrodinger
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>