Solved

Creating Login validation.

Posted on 2007-04-03
8
4,564 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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
 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

636 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