• 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

trouble calling a bean from JSP

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
menu.jsp
--------------------------------
<%@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">
<tr>
<td>
<form>
<input type="hidden" name="action" value="search">
<input type="text" name="keyword" size="10">
<input type="submit" value="go">
</form>
</td>
</tr>
<tr>
<td>category</td>
</tr>
<tr>
<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>");
}
%>
</td>
</tr>
</table>
</body>
</html>
-----------------------------------------------
web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>ControllerServlet</servlet-class>

<init-param>
<param-name>base</param-name>
<param-value>http://localhost:7001/BibleApp/</param-value>;
</init-param>
<init-param>
<param-name>imageURL</param-name>
<param-value>http://localhost:7001/BibleApp/</param-value>;
</init-param>
<init-param>
<param-name>dbURL</param-name>
<param-value>jdbc:weblogic:mssqlserver4:users@COMPAQSERVER</param-value>
</init-param>
<init-param>
<param-name>usernameDbConn</param-name>
<param-value>dinesh</param-value>
</init-param>
<init-param>
<param-name>passwordDbConn</param-name>
<param-value>thisisthepassword</param-value>
</init-param>
</servlet>
</web-app>
--------------------------------------------
DbBean.class
--------------
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) {
dbUrl=url;
}

public void setDbUserName(String userName) {
dbUserName=userName;
}

public void setDbPassword(String password) {
dbPassword=password;
}

public Hashtable getCategories() {
Hashtable categories = new Hashtable();
try
{
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) );
}
rs.close();
cstmt.close();
connection.close();
}
catch (SQLException e) { }
return categories;
}

}





----------------------------------------
[ July 14, 2003: Message edited by: dinesh prasad ]
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is Enumeration.categoryIds or
Enumeration categoryIds.
For Eg:-
Say
Vector v ...
Enumeration e = v.elements() ;
e.hasMoreElements() ;
I'm'nt sure if this'll help you..But thought it might..
 
dinesh prasad
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
Dinesh
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Craig.
 
reply
    Bookmark Topic Watch Topic
  • New Topic