trouble accessing a data bean through JSP

Discussion in 'Java' started by dinesh, Jul 15, 2003.

  1. dinesh

    dinesh Guest

    Hi. I'm trying to call a database access bean through a JSP. (the search
    field is irrelevent, it's referencing a controlling servlet) 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;
    }

    }
    dinesh, Jul 15, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benjamin Stewart

    To bean or not to bean...

    Benjamin Stewart, Jun 30, 2003, in forum: Java
    Replies:
    0
    Views:
    804
    Benjamin Stewart
    Jun 30, 2003
  2. David Thielen
    Replies:
    2
    Views:
    789
    Marek Lange
    Sep 12, 2003
  3. dinesh prasad

    Prblems accessing a bean from JSP

    dinesh prasad, Oct 20, 2003, in forum: Java
    Replies:
    1
    Views:
    693
    Jon Martin Solaas
    Oct 20, 2003
  4. kumar
    Replies:
    1
    Views:
    541
    Wendy S
    Feb 13, 2004
  5. Agent86
    Replies:
    6
    Views:
    2,899
    Tim Slattery
    Oct 24, 2008
Loading...

Share This Page