This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Part of the code is not working in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Part of the code is not working in jsp" Watch "Part of the code is not working in jsp" New topic

Part of the code is not working in jsp

Rashmi Dupati

Joined: Mar 05, 2007
Posts: 22

please check the code and give the solution to my problem.

<%@ page import="java.util.*" %>
<jsp:useBean id="dbBean" scope="application" class="burnaby.DbBean"/>
String base = (String) application.getAttribute("base");
<FONT FACE="Verdana">Search</FONT>
<INPUT TYPE="HIDDEN" NAME="action" VALUE="search">
<INPUT TYPE="TEXT" NAME="keyword" SIZE="10">
<TD BGCOLOR="F6F6F6"><FONT FACE="Verdana">Categories:</FONT></TD>

(up to this working fine the below scriplet is not's not displaying categories accessing from database)

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) +

and see the DbBean code also

public Hashtable getCategories() {
Hashtable categories = new Hashtable();
try {
Connection connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
System.out.println("got connection"+dbUrl);
Statement s = connection.createStatement();
String sql = "SELECT categoryId, category FROM Categories" +
" ";
ResultSet rs = s.executeQuery(sql);
while ( {
categories.put(rs.getString(1), rs.getString(2) );
catch (SQLException e) {}
return categories;

thanks in advance
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70

Well, if nothing is printed out in your HTML, probably your ResultSet has no rows. I believe you could try to add a print statement to check that.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60765

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Santosh Kolekar

Joined: Jul 10, 2008
Posts: 6
Hi Rashmi,

you have not post what err you getting. plese post err msg.
Also check whether it works by following change.

Enumeration categoryIds = categories.iterator();


Santosh Kolekar<br />SCJP,SCWCD,Preparing..SCBCD
Santosh Kolekar

Joined: Jul 10, 2008
Posts: 6
Hi Rashmi,

Try it by iterator.

in my previous post i mentioned
Enumeration categoryIds = categories.iterator();
plese replace it as
Iterator categoryIds = categories.iterator();

All The Best
It is sorta covered in the JavaRanch Style Guide.
subject: Part of the code is not working in jsp
Similar Threads
how to connect to database and display query vqlus using proper java/jsp
view record from database using click event in jsp
trouble calling a bean from JSP
Multiple forms in a single JSP page
Help with JSP!!!