jQuery in Action, 3rd edition
The moose likes JSP and the fly likes trouble calling a bean from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "trouble calling a bean from JSP" Watch "trouble calling a bean from JSP" New topic

trouble calling a bean from JSP

dinesh prasad

Joined: Jun 03, 2003
Posts: 27
Hi. I'm trying to call a database access bean through a JSP. (the search field is irrelevent it's referencing to a controlling servlet)
I get the following error:
C:\bea\user_projects\infologic1\.\myserver\.wlnotdelete\extract\myserver_BibleApp_BibleApp\jsp_servlet\__menu.java:146: cannot resolve symbol probably occurred due to an error in /menu.jsp line 27: Enumeration.categoryIds = categories.keys();

Here's my code:
<%@page import="java.util.*"%>
<jsp:useBean id="DbBean" scope="application" class="showMeItNow.DbBean"/>
String base = (String) application.getAttribute("base");

<table width="150" cellpadding="5" height="75" cellspacing="0" border="0">
<input type="hidden" name="action" value="search">
<input type="text" name="keyword" size="10">
<input type="submit" value="go">
<tr valign="top">
Hashtable categories = DbBean.getCategories();
Enumeration.categoryIds = categories.keys();
while (categoryIds.hasMoreElements()) {
Object categoryId = categoryIds.nextElement();
out.println("<a href=" + base + "? action=browseCatalog&categoryId=" + categoryId.toString() + ">" + categories.get(categoryId) + "</a><br>");
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

package showMeItNow;
import java.util.*;
import java.sql.*;
import showMeItNow.Poll;
public class DbBean {
public String dbUrl="";
public String dbUserName="";
public String dbPassword="";

public void setDbUrl(String url) {

public void setDbUserName(String userName) {

public void setDbPassword(String password) {

public Hashtable getCategories() {
Hashtable categories = new Hashtable();
Connection connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);

CallableStatement cstmt = connection.prepareCall("{? = call dbo.categoryListing()}");
//register the stored procedure's output paramater!!!
cstmt.registerOutParameter(1, java.sql.Types.VARCHAR);
cstmt.registerOutParameter(2, java.sql.Types.VARCHAR);
ResultSet rs = cstmt.executeQuery();
while (rs.next()) {
categories.put(rs.getString(1), rs.getString(2) );
catch (SQLException e) { }
return categories;


[ July 14, 2003: Message edited by: dinesh prasad ]
kalpana Kumar
Ranch Hand

Joined: Jul 03, 2003
Posts: 65
Is Enumeration.categoryIds or
Enumeration categoryIds.
For Eg:-
Vector v ...
Enumeration e = v.elements() ;
e.hasMoreElements() ;
I'm'nt sure if this'll help you..But thought it might..
dinesh prasad

Joined: Jun 03, 2003
Posts: 27
oops, yeah it's supposed to be
Enumeration categoryIds
It will display the page now, but it is blank. It's now showing any data. Any more ideas? thanks..
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Well, I see a couple of statements you may have a an issue with:
1. When you do get the menu(menu.jsp) page to display your link(s), it will not work because there is space after the "? ".
It should be "?action=browseCatalog".
2. I am assuming your setting and creating your showMeItnow.DbName inside your controller servlet.
But anyway it appears you are generating some type of SQLException error in your Try block code.
You are handling the exception by passing back a reference to an empty Hashtable. This is why your menu page is blank. This section of code requires more debugging.
I agree. Here's the link: http://aspose.com/file-tools
subject: trouble calling a bean from JSP
It's not a secret anymore!