Solved

Login validation

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

19 Experts available now in Live!

Get 1:1 Help Now