User Authentication Form Using Servlet

Home  »  Java  »  Advance Java  »  Java Servlets  »  User Authentication Form


The following is an authentication form, which validates the Login ID and Password keyed in by the user and returns an appropriate page generated by a Servlet code. First of all you will create one table in M.S Access as shown below:

Table Definitions:

Table Name: login[SchoolDemo.mdb]
Primary Key: Nil
Foreign Key: Nil

Column Definition:
Column NameData TypeWidth
LoginnameText20
PasswordText20

Table Description:
Column NameDescription
LoginnameIdentification of the person filling the Login form.
PasswordPassword entered by the person


Explanation:

When the user submits the login name and password. A check is made in the table for that user name and password. If the user name and password match a single entry a welcome page will be returned, or else access denied page will be returned.

After create table in M.S. Access database now you will create DSN.

Test Records:
login[SchoolDemo.mdb]
LoginnamePassword
lauracath
mirellamrsbean
bintu12345


Following is the source code of the HTML page i.e. Login.html:



The following is the source code for "login.java:



To run the above servlet program , first of all run Apache Tomcat from "Start -> All Programs -> Apache Tomcat 4.0 -> Start Tomcat."

Now compile Java Servlet Program using below command as shown diagram 24.22

Diagram 24.22 Compile Java Servlet

Now, copy "SimpleServlet.class" File and then paste it under

"C:/Program Files/Apache Tomcat 4.0/webapps/examples/WEB-INF/classes/"

Now, open your any web browser and type html URL where you saved your login.html file. for example:

Diagram 24.23 Output of Login.html

Diagram 24.23 Output of login.class for a valid username and password

Diagram 24.24 Output of login.class for an invalid username and password




Java Servlet Programming







No comments:

Post a Comment