tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uronis, Jeremy" <Jeremy.Uro...@usa.xerox.com>
Subject Help getting beans working
Date Mon, 30 Apr 2001 19:07:14 GMT
hiya-

i have a simple jsp which includes a bean. the file "bean1.jsp" is
located in "C:\tomcat\webapps\examples\jsp\test\bean1.jsp"
i did this following the faq on beans and jsp's.


   "To use the default, put all your JSP source under /examples/jsp, either 
   in the same directory or under a new subdirectory of /examples/jsp (as
   done in the included examples)." 

here is my jsp


<html>
 <body>
 <!- Find and instantiate the bean, and refer to it as myBean -->
 <jsp:useBean id="myBean" scope="page" class= "rayexamples.bean1"/>
 STEP-1 Use the bean's default property "World"<BR>
 Hello there, <%= myBean.getName() %><BR>
 Hi there, <jsp:getProperty name="myBean" property="name" /><BR>
 Howdy, <%= myBean.makeMeBig() %><BR><BR>
 STEP-2 Set the name property to "Sam", using jsp:setProperty
value="Sam"<BR>
 <jsp:setProperty name="myBean" property="name" value= "Sam"/>
 STEP-3 Use the bean's new property "Sam"<BR>
 Hello there, <%= myBean.getName() %><BR>
 Hi there, <jsp:getProperty name="myBean" property="name" /><BR>
 Howdy, <%=myBean.makeMeBig() %> <BR><BR>
 STEP-4 Set the name property to "Bernie", using setName()
 value= "Bernie"<BR>
 <% myBean.setName("Bernie");%> 
 STEP-5 Use the bean's new property"Bernie"<BR> 
	 Hello there, <%=myBean.getName() %><BR>
 Hi there, <jsp:getProperty name="myBean" property="name" /><BR>
 Howdy, <%= myBean.makeMeBig()%> <BR><BR>
 STEP-6 Set the name property from the query string using jsp:setProperty
param="name"<BR>
 <jsp:setProperty name="myBean" property="name" param="name" />
 STEP-7 Use the bean's new property from the URL <BR>
 Hello there, <%= myBean.getName() %><BR>
 Hi there, <jsp:getProperty name="myBean" property="name" /><BR>
 Howdy, <%= myBean.makeMeBig() %> <BR><BR>
 </body>
</html>



now the faq says this on beans:

   Put all your beans (class files) under
   /examples/WEB-INF/jsp/beans appropriately (as done for the included 
   beans). The startserver script will automatically add these classes to 
   the CLASSPATH at runtime.

here is my bean 

package rayexamples ;
import java.io.Serializable ;
public class bean1 implements Serializable{

	String name ;
	/* The JavaBean's empty constructor */
	public bean1(){
		name = "World" ;
	}

	/* THE SETTER METHOD - property returned to the JSP setProperty()*/
	public void setName(String name){
		this.name = name;
	}

	/* THE GETTER METHOD - property is set by the JSP setProperty().
	If nothing is entered in the JSP, then name = World.
	Otherwise, name is set to the name passed here from the JSP. */
	public String getName(){
		return name;
	}

	/* THIS IS AN EXPOSED METHOD. It appends the word Big to the
beginning of the name string. This
	kind of method may be used for enforcing business rules, formatting
	the output, etc. */
	public String makeMeBig(){
		name = "Big " + name ;
	return name ;
	}
} 


i put my bean1.class here in
"C:\tomcat\webapps\examples\WEB-INF\jsp\beans\test\bean1.jsp."
however, by looking at the other exmaples, their class files seem to be here
"C:\tomcat\webapps\examples\WEB-INF\classes\EXAMPLE_FOLDER". so, i tried
placing "bean1.clas"
in "C:\tomcat\webapps\examples\WEB-INF\classes\test\bean1.class" as well,
with no luck.



the error i get follows:



Error: 500
Location: /examples/jsp/test/bean1.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to load class rayexamples.bean1
	at
org.apache.jasper.compiler.BeanRepository.getBeanType(BeanRepository.java:18
3)
	at
org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerato
r.java:99)
	at
org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(J
spParseEventListener.java:773)
	at
org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventLi
stener.java:220)
	at
org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseE
ventListener.java:175)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:183)
	at
org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:462)
	at
org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
	at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:433)
	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspSe
rvlet.java:152)
	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja
va:164)
	at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
	at org.apache.tomcat.core.Handler.service(Handler.java:286)
	at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
	at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection
(Ajp12ConnectionHandler.java:166)
	at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
	at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
	at java.lang.Thread.run(Thread.java:484)

Root cause: 
java.lang.ClassNotFoundException: Unable to load class rayexamples.bean1
	at
org.apache.jasper.servlet.JasperLoader.findClass(JasperLoader.java:223)
	at
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:147)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
	at
org.apache.jasper.compiler.BeanRepository.getBeanType(BeanRepository.java:18
1)
	at
org.apache.jasper.compiler.GetPropertyGenerator.generate(GetPropertyGenerato
r.java:99)
	at
org.apache.jasper.compiler.JspParseEventListener$GeneratorWrapper.generate(J
spParseEventListener.java:773)
	at
org.apache.jasper.compiler.JspParseEventListener.generateAll(JspParseEventLi
stener.java:220)
	at
org.apache.jasper.compiler.JspParseEventListener.endPageProcessing(JspParseE
ventListener.java:175)
	at org.apache.jasper.compiler.Compiler.compile(Compiler.java:183)
	at
org.apache.jasper.servlet.JspServlet.doLoadJSP(JspServlet.java:462)
	at
org.apache.jasper.servlet.JasperLoader12.loadJSP(JasperLoader12.java:146)
	at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:433)
	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspSe
rvlet.java:152)
	at
org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.ja
va:164)
	at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:318)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
	at org.apache.tomcat.core.Handler.service(Handler.java:286)
	at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
	at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
	at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
	at
org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection
(Ajp12ConnectionHandler.java:166)
	at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
	at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
	at java.lang.Thread.run(Thread.java:484)


any help would be great.
thanks - jeremy


Mime
View raw message