Creating Login validation.

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






sivakuganAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sivakuganAuthor Commented:
Can someone plz answer for my question?
0
KuldeepchaturvediCommented:
whats the error you are reiciving?
0
sivakuganAuthor Commented:
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
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

KuldeepchaturvediCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sivakuganAuthor Commented:
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
KuldeepchaturvediCommented:
you can use two methods..

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

0
sivakuganAuthor Commented:
once again thanks kuldeep.

0
KuldeepchaturvediCommented:
we are here to help mate.....:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.