Ibrahimsairafi
asked on
Login validation
Hello,
I have a problrm in validation the user name and pass ,I want in the login page when the user enter a null
user name or pass diectly trnsfer loginerror.jsp or give invalid user name and password this my code
<%@ page import= "dds.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.util.*" %>
<%@ page contentType="text/html;cha rset=UTF-8 "%>
<%
boolean authenticated = false;
String err = new String("");
String UserChecked = new String("");
String user =request.getParameter("Inp ut_User_ID ");
String password = request.getParameter("Inpu t_Password ");
System.out.println(user);
if(user != null && password != null ){
User DDSUser = new User();
UserChecked = DDSUser.VerifyUser(user,pa ssword);
System.out.println(UserChe cked);
if (UserChecked.equals("OK")) {
authenticated = true;
HttpSession mysession = request.getSession(true);
mysession.setAttribute("Au thenticate d","TRUE") ;
mysession.setAttribute("Us er",user);
} else {
authenticated = false;
}
DDSUser.Close();
}
%>
<html>
<head>
<title>Main</title>
</head>
<body>
<% if (!authenticated) {
%>
<form action="login.jsp" method=post>
<div id="Layer1" style="position:absolute; z-index:1; left:0px; top:0px"> <img border="0" src="logo.gif" width="224" height="41">
<hr width="100%" size="4" align=left style="color:#FF0000"></di v><div id="Layer2" style="position:absolute; z-index:2; left:0px; top:0px"> </div><p>&n bsp;</p>
<p> </p>
<p> </p>
<div align="left"><table border="0" cellpadding="2" cellspacing="0" width="99%">
<tr>
<td width="499"><div align="left"><p><font face="Verdana" size="3"><b>
&n bsp; System</b></font></td>
<td width="485"><div align="right"><p><i><font size="2" face="Verdana">
<%
Calendar cal = Calendar.getInstance();
java.util.Date today = cal.getTime();
out.println(""+today);
%></font></i></td>
</tr>
</table>
</div><p style="text-indent: 0; margin: 0"> </p>
<p style="text-indent: 0; margin: 0"> </p>
<div align="left"><table border="0" cellpadding="2" cellspacing="0" width="889">
<tr>
<td width="23"></td>
<td width="213"><font size="2" face="Verdana">User ID:</font></td>
<td width="635"><input type="text" name="Input_User_ID" size="15"></td>
</tr>
<tr>
<td width="23"></td>
<td width="213"></td>
<td width="635"></td>
</tr>
<tr>
<td width="23"></td>
<td width="213"><font size="2" face="Verdana">Password:</ font></td>
<td width="635"><input type="password" name="Input_Password" size="6"></td>
</tr>
<tr>
<td width="23"></td>
<td width="213"><p style="text-indent: 0; margin: 0"> </p>
<p style="text-indent: 0; margin: 0"> </td>
<td width="635"></td>
</tr>
<tr>
<td width="23"></td>
<td width="848" colspan="2"><div align="left"><p><input type="submit" value="Login"
name="B1"> <input type="reset"
value="Reset" name="B2"></td>
</tr>
<td width="23"></td>
<TD>
<p> </p>
<p align="left"><font color=red><% response.sendRedirect("log inerr.jsp" );
%></font></p>
<td>
</table>
</div>
</form>
<tr>
</tr>
<%}else{
response.sendRedirect("sea rch.jsp");
}%>
</body>
</html>
I have a problrm in validation the user name and pass ,I want in the login page when the user enter a null
user name or pass diectly trnsfer loginerror.jsp or give invalid user name and password this my code
<%@ page import= "dds.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.util.*" %>
<%@ page contentType="text/html;cha
<%
boolean authenticated = false;
String err = new String("");
String UserChecked = new String("");
String user =request.getParameter("Inp
String password = request.getParameter("Inpu
System.out.println(user);
if(user != null && password != null ){
User DDSUser = new User();
UserChecked = DDSUser.VerifyUser(user,pa
System.out.println(UserChe
if (UserChecked.equals("OK"))
authenticated = true;
HttpSession mysession = request.getSession(true);
mysession.setAttribute("Au
mysession.setAttribute("Us
} else {
authenticated = false;
}
DDSUser.Close();
}
%>
<html>
<head>
<title>Main</title>
</head>
<body>
<% if (!authenticated) {
%>
<form action="login.jsp" method=post>
<div id="Layer1" style="position:absolute; z-index:1; left:0px; top:0px"> <img border="0" src="logo.gif" width="224" height="41">
<hr width="100%" size="4" align=left style="color:#FF0000"></di
<p> </p>
<p> </p>
<div align="left"><table border="0" cellpadding="2" cellspacing="0" width="99%">
<tr>
<td width="499"><div align="left"><p><font face="Verdana" size="3"><b>
&n
<td width="485"><div align="right"><p><i><font size="2" face="Verdana">
<%
Calendar cal = Calendar.getInstance();
java.util.Date today = cal.getTime();
out.println(""+today);
%></font></i></td>
</tr>
</table>
</div><p style="text-indent: 0; margin: 0"> </p>
<p style="text-indent: 0; margin: 0"> </p>
<div align="left"><table border="0" cellpadding="2" cellspacing="0" width="889">
<tr>
<td width="23"></td>
<td width="213"><font size="2" face="Verdana">User ID:</font></td>
<td width="635"><input type="text" name="Input_User_ID" size="15"></td>
</tr>
<tr>
<td width="23"></td>
<td width="213"></td>
<td width="635"></td>
</tr>
<tr>
<td width="23"></td>
<td width="213"><font size="2" face="Verdana">Password:</
<td width="635"><input type="password" name="Input_Password" size="6"></td>
</tr>
<tr>
<td width="23"></td>
<td width="213"><p style="text-indent: 0; margin: 0"> </p>
<p style="text-indent: 0; margin: 0"> </td>
<td width="635"></td>
</tr>
<tr>
<td width="23"></td>
<td width="848" colspan="2"><div align="left"><p><input type="submit" value="Login"
name="B1"> <input type="reset"
value="Reset" name="B2"></td>
</tr>
<td width="23"></td>
<TD>
<p> </p>
<p align="left"><font color=red><% response.sendRedirect("log
%></font></p>
<td>
</table>
</div>
</form>
<tr>
</tr>
<%}else{
response.sendRedirect("sea
}%>
</body>
</html>
ASKER
yeah it gaves me
org.apache.jasper.JasperEx ception: java.lang.NullPointerExcep tion
org.apache.jasper.servlet. JspServlet Wrapper.ha ndleJspExc eption(Jsp ServletWra pper.java: 532)
org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:4 26)
org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:320)
org.apache.jasper.servlet. JspServlet .service(J spServlet. java:266)
javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 803)
org.apache.jasper.JasperEx
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
org.apache.jasper.servlet.
javax.servlet.http.HttpSer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check if any exception is thrown. Better to have the redirect code after the local try-catch for authenticating the user