Simple.
Create a user login screen in jsp then do an if /else statement. If the user/pass is not equal to the database record of user/pass
then redirect it to another page else if its valid redirect it to the correct page
Here is what I do, I get the fields of the jsp page the pass it to my servlet which verifies and redirects the user.
try {
String user = request.getParameter("fld1
String pass = request.getParameter("fld2
if(user.equals("") && pass.equals("")) {
response.sendRedirect("ind
}
// MySQL Server Direct Connection
Class.forName("com.mysql.j
con = DriverManager.getConnectio
stmt = con.createStatement();
query = "SELECT * FROM Records WHERE Login = '"+user+"'";
rs = stmt.executeQuery(query);
while(rs.next())
{
String val1 = rs.getString(4);
String val2 = rs.getString(5);
if (val1.equals(user) && val2.equals(pass)) {
HttpSession session = request.getSession(true);
session.setAttribute("SOME
RequestDispatcher rd = request.getRequestDispatch
rd.forward(request, response) ;
}
else {
out.println("<html>");
out.println("<title>::: Demo :::</title><body>");
out.println("Sorry Wrong Login !");
out.println("</body></html
}
}
stmt.close();
out.close();
}
catch(InstantiationExcepti
w.printStackTrace();
}
catch(IllegalAccessExcepti
x.printStackTrace();
}
catch(ClassNotFoundExcepti
y.printStackTrace();
}
catch(SQLException z) {
z.printStackTrace();
}
Hope that helps . . .
Javatm
Main Topics
Browse All Topics





by: objectsPosted on 2005-10-03 at 00:41:23ID: 15004755
why container managed? Form managed is a bit more flexible:
132383/sto ries/2004/ 04/23/ usin gFormBased Authentica tion.html
http://radio.weblogs.com/0