wood burning stoves 2.0*
The moose likes JSP and the fly likes Jsp bean error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp bean error" Watch "Jsp bean error" New topic
Author

Jsp bean error

X V Jay
Greenhorn

Joined: Dec 27, 2003
Posts: 6
Hi,
I have been unable to use jsp beans.
Here are the code fragments....
ControllerServlet.java
public class ControllerServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
.....
.....
// instantiate the DbBean
DatabaseBean databaseBean = new DatabaseBean();
// intialise the bean's fields
databaseBean.setDbUrl(config.getInitParameter("dbUrl"));
databaseBean.setDbUserName(config.getInitParameter("dbUserName"));
databaseBean.setDbPassword(config.getInitParameter("dbPassword"));
// put the bean in the servlet context
context.setAttribute("theBean",databaseBean);
}
......
......
}
I am now trying to use the databaseBean in process.jsp
<%@ page import="java.util.*" %>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<jsp:useBean id="theBean" scope="application" class="DatabaseBean" />
<jsp:setProperty name="theBean" property="username"/>
<jsp:setProperty name="theBean" property="password"/>
.......
.......
This is error reported by Tomcat.

exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 5 in the jsp file: /jsp/student/process.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\jakarta-tomcat-4.1.27\work\Standalone\localhost\disa\jsp\student\process_jsp.java:47: cannot resolve symbol
symbol : class DatabaseBean
location: class org.apache.jsp.process_jsp
DatabaseBean theBean = null;
^
An error occurred at line: 5 in the jsp file: /jsp/student/process.jsp
Generated servlet error:
C:\jakarta-tomcat-4.1.27\work\Standalone\localhost\disa\jsp\student\process_jsp.java:49: cannot resolve symbol
symbol : class DatabaseBean
location: class org.apache.jsp.process_jsp
theBean = (DatabaseBean) pageContext.getAttribute("theBean", PageContext.APPLICATION_SCOPE);
^
An error occurred at line: 5 in the jsp file: /jsp/student/process.jsp
Generated servlet error:
C:\jakarta-tomcat-4.1.27\work\Standalone\localhost\disa\jsp\student\process_jsp.java:52: cannot resolve symbol
symbol : class DatabaseBean
location: class org.apache.jsp.process_jsp
theBean = (DatabaseBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "DatabaseBean");
^
3 errors

What's wrong? Please help.
Regards
Jay
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Welcome to the Ranch Jay!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Now as to your question: sounds to me like your DatabaseBean class is not in the classpath.
Where have you placed the class file?
bear
X V Jay
Greenhorn

Joined: Dec 27, 2003
Posts: 6
The class files are in WEB-INF/classes.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Also just noticed that your class is not in a package. Some servlet containers really freak out at this. I'd advise you to place your bean class in a package (which is just good Java practice to begin with).
By the way, changing your display name is not optional. Please be sure to comply with the naming policy before posting.
bear
 
jQuery in Action, 2nd edition
 
subject: Jsp bean error
 
Similar Threads
Unable to find class
calling javabean from jsp
bean error
File Uploading using Jsp and Servlets.
File Upload using Jsp and servlets...