?
Solved

jsp login using a access database

Posted on 2008-02-02
3
Medium Priority
?
2,612 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:tdawg6
3 Comments
 
LVL 6

Accepted Solution

by:
mohammedf earned 2000 total points
ID: 20804784
here is a full working application
http://rapidshare.com/files/88611787/jhtp5.rar.html
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 20808031
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.
0
 
LVL 1

Expert Comment

by:pronane
ID: 20840159
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
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question