Solved

Creating Login validation.

Posted on 2007-04-03
8
4,557 Views
Last Modified: 2013-11-24
Hello all,
I'm creating a login page with two conditions of validation. first i've created the validation. but it's not working. Can someone say wat's wrong in this coding?...Actually i didn't code the login yet, i'm trying to validate the input first.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;


public class login extends HttpServlet
{



      public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
      {

            response.setContentType("text/html");
            PrintWriter out=response.getWriter();

            String StrEma = request.getParameter("email");
            String StrPwd = request.getParameter("password");

            /************************************************************
            ** call a method to validate the password which will return the
            ** email for authorized users and null string for un-authorised.
            **********************************************************/

            // if password only null .. direct to registration page.

            

            if (StrPwd == null)
            {
                  out.println("<HTML>");
                  out.println("<BODY>");
                  out.println("<FORM METHOD=\"GET\" ACTION=\"forwarded url\">");
                  out.println("</FORM>");
                  out.println("</BODY>");
                  out.println("</HTML>");      
                  
            }

            //// if password and email is null .. direct to error page.



            if (StrEma == null && StrPwd == null)

            {

                  out.println("<HTML>");
                  out.println("<BODY>");
                  out.println("<FORM METHOD=\"GET\" ACTION=\"http://forwarded url\">");
                  out.println("<H1>Registration Error</H1><p>");
                  out.println("Fields cannot be empty<br>");                        
                  out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Go to Registration\">");
                  out.println("</FORM>");
                  out.println("</BODY>");
                  out.println("</HTML>");

            }

            
            

            // So the user is valid let's create a session // for this user.

            //HttpSession userSession = request.getSession(true);

            // put the user name session variable.

            //userSession.putValue("userName", uName);

            // now we need to transfer the control to race page

            




            
















      }



}

thanks






0
Comment
Question by:sivakugan
  • 4
  • 4
8 Comments
 

Author Comment

by:sivakugan
ID: 18847006
Can someone plz answer for my question?
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 18847548
whats the error you are reiciving?
0
 

Author Comment

by:sivakugan
ID: 18847735
It's not validating the input. If user leave fields as empty and then press the login button, it just give me the blank page intead of  "the fields cannot be empty" or go to login page.
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 500 total points
ID: 18847755
its because you are checking for null and not spaces..!!!..

If the HTML form has a field, the field will come to the servlet... hence it will not be null ever...
you should check for blanks..


 if (StrEma.trim().equals("") && StrPwd.trim().equals(""))
0
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.

 

Author Comment

by:sivakugan
ID: 18847949
Hi kuldeep,

well spoted..Thanks for that. but there is a small issue in forward to another page.
If (StrEma.trim().equals("") )
{
  forward to desired page.
}

How to forward to desired page in servlet?...
I don't want to use hyperlink. i want to forward to particular page for the above condition..
How can I do that?.....

Thanks
regards siva
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 18848011
you can use two methods..

response.sendRedirect()
or .forward()....

0
 

Author Comment

by:sivakugan
ID: 18848118
once again thanks kuldeep.

0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 18848122
we are here to help mate.....:-)
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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

948 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

22 Experts available now in Live!

Get 1:1 Help Now