Solved

Creating Login validation.

Posted on 2007-04-03
8
4,555 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
Comment Utility
Can someone plz answer for my question?
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
Comment Utility
whats the error you are reiciving?
0
 

Author Comment

by:sivakugan
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:sivakugan
Comment Utility
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
Comment Utility
you can use two methods..

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

0
 

Author Comment

by:sivakugan
Comment Utility
once again thanks kuldeep.

0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
Comment Utility
we are here to help mate.....:-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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.

743 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

18 Experts available now in Live!

Get 1:1 Help Now