Hi !

I am new to JSP and am trying to connect to Oracle using the following :

<%@ page language="java" import ="java.util.*"
contentType="text/html;charset=WINDOWS-1252"  %>

<jsp:useBean id="con" scope="session"
class="conn_package.Connection_Manager" />
<jsp:setProperty name="con" property="driverClass"
value="oracle.jdbc.driver.OracleDriver" />
<jsp:setProperty name="con" property="connectionUrl"
value="jdbc:oracle:thin:@winnt-dev:1521:esca" />
<jsp:setProperty name="con" property="debug" value="true" />

<jsp:useBean id = "app" scope="session" class="conn_package.Prgm_bean" />


<%
  app.setConnectionManager(con);
  con.processRequest(request);
  con.logon();
%>
<%
if (app.isConnected() ) { %>
<jsp:forward page="rcms_main.jsp" />

 <%}
else {%>
<jsp:forward page="LoginUser.html" />

<%
      }
%>

When I run this, it is not going to the else clause at all even when I give
a wrong login meaning app.isConnected() always evaluates to true.

Can somebody help out please.

I have given Prgm_bean also below.




package conn_package;

/**
 * A Bean class.
 *
 */
import java.io.*;
import java.util.*;
import java.beans.*;
import java.sql.*;
import javax.servlet.http.*;
import javax.servlet.jsp.JspWriter;



public class Prgm_bean implements PropertyChangeListener, AppConstants
{

  /**
   * Constructor
   */
  public Prgm_bean()
  {
  }

  /************************
         * Implemetation of PropertyChangeListener. Listens for successful
         * or unsuccessful database connections and manages them
         * accordingly.
         * @param PropertyChangeEvent
         **********************/
        public void propertyChange(PropertyChangeEvent evt)
  {
                String prop = evt.getPropertyName();
                //see if we got a connection
                if (prop.equals(connection))
    {
                        //ok so update the local connection
                        try
        { //make sure it really is a connection
                      con = (Connection)evt.getNewValue();
                                }
       catch(Exception ex)
        {
                                        handleConError(ex);
                          }
                }
                else if (prop.equals(conError))
      { //no good connection
                                 try
         {
                                    if (debug)
                                        handleConError(
(Exception)evt.getNewValue() );
                                 }
                                 catch(Exception ex)
         { //not an exception in the obj handle anyway
                                     if (debug)
                                        handleConError( ex );
                                 }
                        }
         }
 /********************
         * Returns a true if connection not null.
         * @return boolean
         ***********/
        public boolean isConnected(){
                return (con != null);
        }
  /*******************
         * Manages the connection error string.
         * @param Exception the exception to manage.
         **************/
        protected void handleConError(Exception ex){
                writer.writeDebug("Error connecting to database: "+
ex.getMessage() );
        }

  public void setConnectionManager(conn_package.Connection_Manager cm)
  {
    if (cm != null)
    {
      cm.removePropertyChangeListener( this );
      conMan = cm;
      cm.addPropertyChangeListener( this );
      if (debug)
              writer.writeDebug("JspApp; Set connection manager " +
cm.toString());
      else
      {
        if (debug)
                                  writer.writeDebug("JspAPP; Tried to set a
null connection manager");
      }
    }
  }
  //the bundle
    protected ResourceBundle bundle;
        /** The database connection - may be null*/
        protected Connection con;
        /** The connection manager */
        Connection_Manager conMan;
     /** The current locale */
     protected Locale currentLocale;
        /** The debug boolean - default false*/
        private boolean debug = false;
     /** The default bundle for this class.*/
        protected String defaultBundle =
"com/wrox/projsp/ch04/JspAppBundle";
        /** The log hanlder class*/
        protected DebugWriter writer;   /** The selection query boolean for
running a select query - default true */
        private boolean selectQuery = true;
        /** The result element tracker */
        private int resultElement = 0;
        /** The results Vector */
        private Vector resultsVector = new Vector();
        /** The SQL String to execute */
        protected String sql ="";
        /** The most recent updated, inserted or deleted number of records
*/
        private int edited = -1;
}


Thanks and regards
Vijay

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to