Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating a Loginpage.jsp in JSP with LOGIN id and Password.

 
kanna prasanth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,
To get to know the concept can anyone answer my questions in detail along with an example.

first step: Have to create a Loginpage.jsp in JSP with LOGIN id and Password.
second step: I am using MS Access as my present database which stores name and password.
Third step: Please explain to me how connection is made between Access and My Loginpage.jsp and what needs to be done in control panel(i donno that too).

Fourth step: This loginpage.jsp shld validate user id and password and if they are correct shld , send it to the next page through session.
[ September 16, 2008: Message edited by: Bear Bibeault ]
 
Sudarshan Chakrabarty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Step 3 :

i )In order to use the MS Access DB, you need to add a Data Source through Ctrl Panel-> Administrative Tools -> Data Sources(ODBC).
ii)Under User DSN, click on Add, select the driver ( in your case, it would be Microsoft Access Driver(*.mdb).
iii) Click on Finish
iv) Provide DataSource name on next screen.
v) Then under Database: click Create and create the DB somewhere on your local system.
vi) For setting password to the DB, click on Advanced button and provide the user name and password.
Click on Finish and you should be all set.

The url for accessing would be
String url = "jdbcdbcataSourceNameYouProvided";

For Step 1, you can a lot of example pages and code in google.
 
kanna prasanth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sudershan thanks for your help,

But i want to know about following pgm please:

The problem is in process.jsp(as attached)the line is if(idHandler.validate()).

please help me with

(----------------html page----------------------------------------)
<html>
<head>
<title>Nouman Rashid page </title>
</head>

<body>
<br>
<p> <h3><center>Please enter your user name and
password</center></h3></p>

<br>
<br>
<form action="process2.jsp " method = "post" >
<center>username</center>
<center><input type = "text" name=
"username"></center>
<center>password</center>
<center><input type = "password" name =
"password"></center>
<center><input type="submit" name="Submit"
value="Login"></center>


</form>

</body>
</html>
(-------------------------------------------------------------------------)





(------------------------------jsp page----------------------------------)


---------process2.jsp-----------------------

<%@ page import="java.util.*" %>
<jsp:useBean id="idHandler" class="foo.Login" scope="request">
<jsp:setProperty name="idHandler" property="*"/>
</jsp:useBean>

<%
if (idHandler.validate()) {
%>
<jsp:forward page="success.jsp"/>
<%
} else {
%>
<jsp:forward page="retry.jsp"/>
<%
}
%>


(-------------------------------------------------------------------------)



(----------------------------------java-----------------------------------)



package foo;
import java.sql.*;

public class Login {

private String username = "";
private String password = "";

public Login() {
}

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}


public boolean authenticate(String username2,
String password2) {
String query="select * from Registration;";
String DbUserName="";
String DbPassword="";
String finalUser="";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbcdbc:register");
Statement stat=con.createStatement();
ResultSet rst=stat.executeQuery(query);
while(rst.next())

{
DbUserName=rst.getString("UserName");

DbPassword=rst.getString("password");

if (username2.equals(DbUserName) &&
password2.equals(DbPassword)) {

break;
}


}
return true;
}catch(Exception e){

e.printStackTrace();
return false;
}
}}



(-------------------------------------------------------------------------)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic