Solved

Login validation

Posted on 2007-04-08
5
3,467 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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