Solved

Login validation

Posted on 2007-04-08
5
3,464 Views
Last Modified: 2008-01-09
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>
0
Comment
Question by:Ibrahimsairafi
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Jaax
ID: 18871802
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
0
 
LVL 1

Author Comment

by:Ibrahimsairafi
ID: 18871839
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)
0
 
LVL 10

Accepted Solution

by:
Jaax earned 250 total points
ID: 18871878
When a non-business exception is thrown, it is better to route to a common System Error page.
You can specify the sysError.jsp like this :
<%@ page errorPage="sysError.jsp" %>
And in sysError.jsp have
<%@ page isErrorPage="true" %>

From the complete stack trace were you able to locate the line that causes the exception. It is not so obvious from your and the partial stack trace


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now