Link to home
Start Free TrialLog in
Avatar of tdawg6
tdawg6

asked on

jsp login using a access database

I am using NetBeans IDE 5.5.1 and I have a Login.jsp and a access database. How do i create a login from my jsp page that reads from my database?
<center>
              UserName
                <input type="text" name="ID" id="ID" />
                
                </form>
                <p>ID &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input type="password" name="Occupation" id="Occupation" />
</p>
 
  <input name="Login" type="button" id="Login" value="Login" />
  </center>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mohammedf
mohammedf
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrcoffee365
Netbeans has good online documentation.  This page:
http://www.netbeans.org/kb/articles/security-webapps.html
walks you through the steps to create a form-based login for Tomcat (or Sun's Web app server).

You don't have to use the mechanism that comes with Tomcat, however.  You could  create a form and have users log in.  Then you could write your own code to keep the pages secure from non-logged in Web site visitors.  It's easier to use a login package, like the one that comes with Tomcat, but you don't have to.

If you are asking how to make a query to an Access db from a JSP, here is a simple example:

Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try
{
      Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
      con = DriverManager.getConnection( "jdbc:odbc:MyDbName", dbUser, dbPassword );
      stmt = con.createStatement( );

      rs = stmt.executeQuery("Select Id, Field1 from Table 1");
      while( rs.next() ) {
            int recId = rs.getInt("Id");
            String field1 = rs.getString("Field1");
      }
}
catch( SQLException e ) {
      e.printStackTrace();
}

This uses the JDBC-ODBC driver to access your Access db.  You have to have an ODBC connection defined for your Access db (as a System DSN), which in this example is named MyDbName.  Access dbs often don't have usernames and passwords.  If you don't, you can leave off the dbUser and dbPassword parameters to the getConnection call.
Avatar of pronane
pronane

rose india does a nice app for you, if you replace the code in the checkValidUser to do a sql select on your DB it will work a treat:

http://www.roseindia.net/jsf/IntegratingLogin_Registration.shtml

ResultSet rs = stmt.executeQuery("select name * from userTable where userId ='1'");

if(rs = null)
           user does not exist
else
      user exists