Link to home
Start Free TrialLog in
Avatar of Ibrahimsairafi
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;charset=UTF-8"%>
<%

         

        boolean authenticated = false;
        String err = new String("");
        String UserChecked = new String("");
        String user =request.getParameter("Input_User_ID");
          String password = request.getParameter("Input_Password");
          
        System.out.println(user);
      if(user != null && password != null ){
      

          User DDSUser = new User();
          UserChecked = DDSUser.VerifyUser(user,password);
          System.out.println(UserChecked);
          if (UserChecked.equals("OK")) {
             authenticated = true;
             HttpSession mysession = request.getSession(true);
             mysession.setAttribute("Authenticated","TRUE");
             mysession.setAttribute("User",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">&nbsp;<img border="0" src="logo.gif" width="224" height="41">
<hr width="100%" size="4" align=left style="color:#FF0000"></div><div id="Layer2" style="position:absolute; z-index:2; left:0px; top:0px">&nbsp;</div><p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</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>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  System</b></font></td>
      <td width="485"><div align="right"><p><i><font size="2" face="Verdana">&nbsp;
      <%
      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">&nbsp;</p>
  <p style="text-indent: 0; margin: 0">&nbsp;</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">&nbsp;</p>
      <p style="text-indent: 0; margin: 0">&nbsp;</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>&nbsp;</p>      
             
                  <p align="left"><font color=red><% response.sendRedirect("loginerr.jsp");
                %></font></p>
            <td>
   
  </table>
  </div>
</form>    
<tr>
                  
             
</tr>
<%}else{
      response.sendRedirect("search.jsp");
}%>

      
</body>
</html>
Avatar of Jaax
Jaax
Flag of India image

Maybe some exceptions is thrown. And that is causing for the else condition to be overlooked.
Check if any exception is thrown. Better to have the redirect code after the local try-catch for authenticating the user
Avatar of Ibrahimsairafi
Ibrahimsairafi

ASKER

yeah it gaves me
org.apache.jasper.JasperException: java.lang.NullPointerException
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
ASKER CERTIFIED SOLUTION
Avatar of Jaax
Jaax
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial