File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble calling a bean from JSP

 
dinesh prasad
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
kalpana Kumar
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Craig Jackson
Ranch Hand
Posts: 405
  • 0
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic