Hi,
I am using jsp and Java Beans for login action.
Here are the code's:
login.jsp
<%@ page language="java" contentType="text/html" import="java.sql.*" %>
<%
String adminid = request.getParameter("adminid");
String username = request.getParameter("username");
String password = request.getParameter("password");
String usertype = request.getParameter("usertype"); %>
<jsp:useBean id="user" class="aa.User" scope="request"/>
<jsp:setProperty name="user" property="*"/>
<%
if(user.login())
{
HttpSession s = request.getSession(true);
s.setAttribute("naam", user.getUserName());
s.setAttribute("passwordAdmin", user.getUserPassword());
s.setAttribute("usertype", user.getUserType());
s.setAttribute("loggedin", "true");
response.sendRedirect("wel.jsp");
}
else{
response.sendRedirect("niet.jsp");
}// end else
%>
.....................................................
The User bean is:
aa.User.java
package aa;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import db.*;
public class User
{
private DBConnectie db = new DBConnectie("fahim","fahim","fahim");
private String username,password,usertype;
private int adminid;
private String usernameDB, passwordDB;
public void setUserName(String username)
{
this.username=username;
}
public String getUserName()
{
return username;
}
public void setUserPassword(String password)
{
this.password=password;
}
public String getUserPassword()
{
return password;
}
public void setUserType(String usertype)
{
this.usertype=usertype;
}
public String getUserType()
{
return usertype;
}
public void setAdminId(int adminid)
{
this.adminid=adminid;
}
public int getAdminId()
{
return adminid;
}
public boolean login()
{
try
{
String sql= "SELECT * FROM admin WHERE Naam='"+username+"' AND passwordAdmin='"+password+"'";
db.connect();
ResultSet result = db.selectQuery(sql);
while(result.next())
{
usernameDB= result.getString("naam");
passwordDB= result.getString("password");
if (usernameDB.equals(username))
{
if (passwordDB.equals(password))
{
//username= result.getString("naam");
// password= result.getString("password");
usertype= result.getString("usertype");
adminid= result.getInt("adminid");
return true;
}
}
}
db.close();
}
catch(Exception e)
{
System.out.println( e.getMessage() );
}
return false;
}
}
.......................................................
And in the Wel.jsp
<%= session.getAttribute( "naam" ) %>
WHEN I AM EXCUTING THIS, I AM GETTIN "NULL", OR, IT ALWAYS GOES TO NIET.JSP, WICH IS NOTHING BUT, ERROR MESSAGE.
WHAT AM I DOING WRONG???
PLEASE HELP.....
I am using jsp and Java Beans for login action.
Here are the code's:
login.jsp
<%@ page language="java" contentType="text/html" import="java.sql.*" %>
<%
String adminid = request.getParameter("adminid");
String username = request.getParameter("username");
String password = request.getParameter("password");
String usertype = request.getParameter("usertype"); %>
<jsp:useBean id="user" class="aa.User" scope="request"/>
<jsp:setProperty name="user" property="*"/>
<%
if(user.login())
{
HttpSession s = request.getSession(true);
s.setAttribute("naam", user.getUserName());
s.setAttribute("passwordAdmin", user.getUserPassword());
s.setAttribute("usertype", user.getUserType());
s.setAttribute("loggedin", "true");
response.sendRedirect("wel.jsp");
}
else{
response.sendRedirect("niet.jsp");
}// end else
%>
.....................................................
The User bean is:
aa.User.java
package aa;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import db.*;
public class User
{
private DBConnectie db = new DBConnectie("fahim","fahim","fahim");
private String username,password,usertype;
private int adminid;
private String usernameDB, passwordDB;
public void setUserName(String username)
{
this.username=username;
}
public String getUserName()
{
return username;
}
public void setUserPassword(String password)
{
this.password=password;
}
public String getUserPassword()
{
return password;
}
public void setUserType(String usertype)
{
this.usertype=usertype;
}
public String getUserType()
{
return usertype;
}
public void setAdminId(int adminid)
{
this.adminid=adminid;
}
public int getAdminId()
{
return adminid;
}
public boolean login()
{
try
{
String sql= "SELECT * FROM admin WHERE Naam='"+username+"' AND passwordAdmin='"+password+"'";
db.connect();
ResultSet result = db.selectQuery(sql);
while(result.next())
{
usernameDB= result.getString("naam");
passwordDB= result.getString("password");
if (usernameDB.equals(username))
{
if (passwordDB.equals(password))
{
//username= result.getString("naam");
// password= result.getString("password");
usertype= result.getString("usertype");
adminid= result.getInt("adminid");
return true;
}
}
}
db.close();
}
catch(Exception e)
{
System.out.println( e.getMessage() );
}
return false;
}
}
.......................................................
And in the Wel.jsp
<%= session.getAttribute( "naam" ) %>
WHEN I AM EXCUTING THIS, I AM GETTIN "NULL", OR, IT ALWAYS GOES TO NIET.JSP, WICH IS NOTHING BUT, ERROR MESSAGE.
WHAT AM I DOING WRONG???
PLEASE HELP.....