Thread: Login page
View Single Post
  #2 (permalink)  
Old 07-02-2008, 12:37 PM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 228
Eku is on a distinguished road
Im using netbeans6.1 but this migth help.
Im also using Java sun application server as my web server which you can download at the sun site

I have a login.jsp which contains a username textfield and a password field a "Login" Button and a "Clear"Button
In the log-in button, i call my LogIn servlet and passes the data in the username and password field using session or request.
The servlet is the one who will test the username and password, it will connect to the database using the select command.
ex:
Code:
Select * from account where in username=? AND password=?
In my database I have a username field, password field, and Access Rigths (to determine admin or Normal user)

After retrieving the data I'll check if i got a hit/miss using if statement.
Code:
ex: If(!rs.getString("username").equals(null)){
that means i got a valid username and password then i go into another series of if-else comparing the access rigths. if i found that it is a admin the servlet shall direct it to the admin page or a normal user into a regular page.
here is how to direct a page:

Code:
request.getRequestDispatcher("AdminPage.jsp").forward(request,response);
else if the servlet found a non-valid username it goes to
Code:
request.getRequestDispatcher("ErrorPage.jsp").forward(request,response);
or you may wish to return it the log in page and give it some error message.

*A few Notes*
-Make sure you configure your web server like Connection pools and JNDI (correct me if i got this one wrong)
-Make sure that the driver of the JDBC is installed and the Web-inf/web.xml is also configured correctly (this is used to declare you servlet for the use of the web server *i dont know how to this in ecllipse*

I hope my idea helps
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.

Last edited by Eku : 07-02-2008 at 12:41 PM.
Reply With Quote