• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jsp bean error

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class files are in WEB-INF/classes.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic