cannot create bean of class...using TOMCAT 3.1
my root is: "notwww.ucsd.edu/somesub/"
my beans are in .../WEB-INF/classes/aseBeans/
the error msg:
Error: 500
Location: /studentaffairs/aseAppValidate.jsp
Internal Servlet Error:
javax.servlet.ServletException: Cannot create bean of class aseBeans.AseApplicationBean
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:386)
at _0002faseAppValidate_0002ejspaseAppValidate_jsp_0._jspService(_0002faseAppValidate_0002ejspaseAppValidate_jsp_0.java:138)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:174)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:156)
at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
at java.lang.Thread.run(Thread.java:496)
Root cause:
javax.servlet.ServletException: Cannot create bean of class aseBeans.AseApplicationBean
at _0002faseAppValidate_0002ejspaseAppValidate_jsp_0._jspService(_0002faseAppValidate_0002ejspaseAppValidate_jsp_0.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:174)
at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261)
at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(Ajp12ConnectionHandler.java:156)
at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338)
at java.lang.Thread.run(Thread.java:496)
I think I have all the necessary elements:
package aseBeans;
pickled my beans
<jsp:useBean id="app" scope="session" class="aseBeans.AseApplicationBean" >
<jsp:setProperty.../>
</jsp:useBean>
MANIFEST.MF was created, are the name/attribute pairs necessary?
Name: AseApplicationBean.class
Java-Bean: true
THANK YOU
[2980 byte] By [
hubertn] at [2007-9-26 3:20:18]

Is the bean implements java.io.Serializable?
Beans don't have to implement serializable as far as I know. I'm having the same problem, I modified one of the tomcat examples and now I get the error message you're getting.
beans don't have to implement serializable, but now that you bring that up...
i wrote:
import java.io.*;
public class AseApplicationBean implements Serializable {...}
mpburke, what did you modify in the example?
I'm guessing my problem has to do with how i'm qualifying my bean class. I know my the engine can find my bean because my jsp wouldnt compile b/c of errors in my bean earlier.
I looked at the corresponding servlet and Beans.instantiate is getting my jsp:useBean attributes, but the catch block throws that servlet exception. It might not like what I'm using as the useBean class attribute.
I have experienced the same problem some time back. This problem was resolved by just adding class in my system's classpath.
class or classes?my classpath is .../WEB-INF/classes/thank you
hubertn I modified the jsp file and the bean: here's the code:<!--
Copyright (c) 1999 The Apache Software Foundation. All rights
reserved.
Number Guess Game
Written by Jason Hunter, CTO, K&A Software
http://www.servlets.com
-->
<%@ page import = "num.NumberGuessBean" %>
<jsp:useBean id="numguess" class="num.NumberGuessBean" scope="session"/>
<jsp:setProperty name="numguess" property="*"/>
<html>
<head><title>Number Guess</title></head>
<body bgcolor="white">
<font size=4>
<% if (numguess.getSuccess()) { %>
Congratulations! You got it.
And after just <%= numguess.getNumGuesses() %> tries.<p>
<% numguess.reset(); %>
Care to <a href="numguess.jsp">try again</a>?
<% } else if (numguess.getNumGuesses() == 0) { %>
Welcome to the Number Guess game.<p>
Play with default limits ( a number between 0 and 100)<p>
or enter upper and lower limits.<p>
<form method=get>
Play with defaults?: <input type=radio name=default value="yes">Yes
<input type=radio name=default value="no">No
</form>
<% if (numguess.getRadio().equals("no")) { %>
<form method=get>
Enter upper limit:<input type=text name=upperLimit>
Enter lower limit:<input type=text name=lowerLimit>
</form>
<% numguess.reset(); %>
<% } %>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } else { %>
Good guess, but nope. Try <b><%= numguess.getHint() %></b>.
You have made <%= numguess.getNumGuesses() %> guesses.<p>
I'm thinking of a number between <jsp:getProperty name="numguess" property="lowerLimit"/> and <jsp:getProperty name="numguess" property="upperLimit"/>.<p>
<form method=get>
What's your guess? <input type=text name=guess>
<input type=submit value="Submit">
</form>
<% } %>
</font>
</body>
</html>
and the bean:
/*
* Originally written by Jason Hunter, http://www.servlets.com.
*/
package num;
import java.util.*;
public class NumberGuessBean {
int answer;
boolean success;
String hint;
int numGuesses;
String radiochoice;
int lowerLimit=0;
int upperLimit=100;
String error;
public NumberGuessBean() {
reset();
}
public void setGuess(String guess) {
numGuesses++;
int g;
try {
g = Integer.parseInt(guess);
}
catch (NumberFormatException e) {
g = -1;
}
if (g == answer) {
success = true;
}
else if (g == -1) {
hint = "a number next time";
}
else if (g < answer) {
hint = "higher";
}
else if (g > answer) {
hint = "lower";
}
}
public void setRadio(String s) {
radiochoice=s;
}
public String getRadio() {
return radiochoice;
}
public void setLowerLimit( int lowerLimit) {
this.lowerLimit=lowerLimit;
}
public int getLowerLimit() {
return lowerLimit;
}
public void setUpperLimit(int upperLimit) {
this.upperLimit=upperLimit;
}
public int getUpperLimit() {
return upperLimit;
}
public boolean getSuccess() {
return success;
}
public String getHint() {
return "" + hint;
}
public String getError() {
return ""+error;
}
public int getNumGuesses() {
return numGuesses;
}
public void reset() {
if (getRadio().equals("yes")) {
answer = (int)(Math.random()*100);
}
else {
int i;
i=(int)(Math.random()*upperLimit);
if (i<lowerLimit) {
i=i+lowerLimit;
}
answer=i;
}
success = false;
numGuesses = 0;
}
}>
That's my question, I get a can't create bean of class.. error when I load this jsp.
Hi,
I have had this problem. The possible causes are :
i) you have not defined the constructor to be public. For a Bean it must be defined as public.
ii) you must import the Class in the page directive on your jsp page
iii) you instatiate the Bean within the useBean jsp tag including the package name.
iv) for TOMCAT the class must be placed within the WEB-INF/classes/your-app-name directory
I think you have ii,iii,iv and perhaps it is i) that is the problem.
It should not be necessary to add the classpath to your system classpath and this is not what you want to do anyway since you want your application to work within a JSP Container.
Hope this of help,
Marcus