• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp bean error

 
X V Jay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class files are in WEB-INF/classes.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic