Solved

Login validation

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

773 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