Jeff, Is there a website for that tutorial? I'd be curious myself to see if such a scenario is possible...
Thanks :) Denise -----Original Message----- From: Jeff Ousley [mailto:[EMAIL PROTECTED]] Sent: Monday, January 13, 2003 7:07 PM To: Tomcat Users List Subject: RE: how do I reference a bean that's inside my jsp page? Denise, Thanks for the response. I got it to work by pulling the bean out into it's own class file. I'm just trying to understand this example from a tutorial I'm going through. It works on their site. However, I'm not sure which app server they are using. -jeff --- Denise Mangano <[EMAIL PROTECTED]> wrote: > Jeff, > > My apologies... I just re-read your post, and it > looks like you actually > want to define your bean within your JSP page... I > do not think this is > possible. I would imagine not because from what I > understand the bean is an > actual class file, which would not be created in > your scenario. Then again, > I could be wrong... However, the scenario I gave > works. > > HTH > Denise > > -----Original Message----- > From: Denise Mangano > [mailto:[EMAIL PROTECTED]] > Sent: Monday, January 13, 2003 6:54 PM > To: 'Tomcat Users List' > Subject: RE: how do I reference a bean that's inside > my jsp page? > > > Jeff, > > I'm not exactly sure what you mean by a bean that is > "inside your JSP" (then > again I'm a newbie...), but I am assuming you mean > have access to a bean > from within your JSP. > > The way I use my bean, is I created the file > MyBean.java with all the proper > methods and compiled it. These files (the .java and > .class) are in the > WEB-INF/classes/com/complusdata/beans directory of > my webapp. Now I've > noticed that I have had to restart Tomcat every time > I make changes to the > bean and recompile, but someone on the list may have > a better solution to > that... > > In MyBean.java I declare > > package com.complusdata.beans; > > To reference the bean from myJSP.jsp that is in my > webapp directory, I have > the following: > > <%@page import="com.complusdata.beans"%> > > <jsp:useBean id="myBean" > class="com.complusdata.beans.MyBean" > scope="request"> > <jsp:setProperty name="myBean" property="*"/> </jsp:useBean> > > As I've learned from the list, this will tell the > JSP to use the bean > "myBean". It will first look for an existing > instance of the bean. If one > does not exist it will execute the body of the > <jsp:useBean> tag. If an > instance does exist it will not execute the body. > Then in either case, you > will have access to the properties of that bean. > > When I want to access a specific value from the bean > within my JSP page, I > use myBean.getPropertyName() - where you substitute "PropertyName" for > the name of your property. I believe you can also use > the tag <jsp:getProperty > name="myBean" property="propertyName"/> > > I also have my webapps directory in my Classpath, > but not sure if that is > required... > > On a side note, anyone feel free to correct me if I > am wrong about something > ;) but Jeff, this is how mine is set up. > > HTH > Denise > > -----Original Message----- > From: Jeff Ousley [mailto:[EMAIL PROTECTED]] > Sent: Monday, January 13, 2003 5:38 PM > To: [EMAIL PROTECTED] > Subject: 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.jav > a:1428) > at > org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.jav > a: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: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>