Username: " name="description">

Login validation doubt

Login validation doubt

Hi,

1)login.jsp:

<%@page import="java.sql.*"%>

Username:
Password:

2)check.jsp:

<% String user=request.getParameter("user"); String pass=request.getParameter("pass"); if(user.equals("")&&pass.equals("")){ response.sendRedirect("login.jsp"); } else{ } %>

Once validating in check.jsp, i want error message on login.jsp like 'username or password is not provided' if username or password is null.

How get above thing.

View Answers

December 14, 2010 at 11:07 AM

Hi Friend,

Try the following code:

1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
  document.getElementById('lab1').innerHTML="<small><font color='red'>Enter Username!</font></small>";
  return false;
}
if(password==""){
  document.getElementById('lab2').innerHTML="<small><font color='red'>Enter Password!</font></small>";
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"><label id="lab1"></label></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"><label id="lab2"></label></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
<%String msg=request.getParameter("msg");
if(msg!=null){
    %>
<label><font color="red"><%=msg%></font></label> 
<%
}
    %>

2)check.jsp:

<%@page import="java.sql.*"%>

<%
String user=request.getParameter("user");
String pass=request.getParameter("pass");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where uname='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            out.println("welcome "+user);
          }
          else
          {
                       response.sendRedirect("login.jsp?msg=Invalid Username or Password");
          }
%>

Thanks









Related Tutorials/Questions & Answers:
Login validation doubt
Login validation doubt  Hi, 1)login.jsp: <%@page import="java.sql.*"%> ADS_TO_REPLACE_1 Username: Password: 2)check.jsp: <...(); ResultSet rs=st.executeQuery("select * from login where uname='"+user+"' and password
Validation doubt
Validation doubt  hi..... thanks for the other validation code. I have got that and implemented in my code but i have a doubt in that. As we try... think i am able to tell u what i want to and u have got whats my doubt. plz give
Advertisements
Login page validation on ipad
Login page validation on ipad  I am using userId & password labels and their corresponding textfield. Now I want to validate the details by single sign in button and want to switch on to next page. Used two labels again
login form validation - JSP-Servlet
login form validation  hi, how to validate the login form that contains user name and password using post method . the validation should not allow user to login in the address bar thanks regards, anand
login page validation
login page validation  hi could you please send me code for login validations Email validation and password email should be in correct format and valid password in java   import java.awt.*; import javax.swing.
Login Password Validation iPhone / iPAD
Login Password Validation iPhone / iPAD  HOW TO WRITE A TEST CASE TO SET THE VALIDATION FOR LOGIN AND PASSWORD FIELD IN OBJECTIVE C, IOS.   @implementation LoginViewTests - (void)testPasswordFieldIsNotEmpty
doubt this
doubt this  what is the use of "this" and "super" keyword
Example of login form validation in struts2.2.1framework.
Example of login form validation in struts2.2.1 framework. In this example, we will introduce you to about the login form validation in struts2.2.1 framework. Our login form validation example does not validate the user against
struts2.2.1 Login validation example.
struts2.2.1 Login validation example. In this example, We will discuss about the Login validation using struts2.2.1. Directory structure of example...;title>Login Validation Example</title> <s:head
DOUBT ?
DOUBT ?  in c++ member function of a class must be public
Doubt
Doubt  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details
Jdbc Login Page Validation using Combobox
Jdbc Login Page Validation using Combobox  I got Login By this code i want to login by validating with combobox....The link which you send its without combobox.i m unable to get login by verifying with combo box..Ex banglore
Jdbc Login Page Validation using Combobox
Jdbc Login Page Validation using Combobox  I am beginer to java i am.../html; charset=UTF-8"> <title>Celcabs Login Page</title> <...; <tr><td colspan="2"><input type="submit" value="Login"><
Jdbc Login Page Validation using Combobox
Jdbc Login Page Validation using Combobox  I am beginer to java i am.../html; charset=UTF-8"> <title>Celcabs Login Page</title> <...; <tr><td colspan="2"><input type="submit" value="Login"><
Doubt
User request form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
How to load page  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action="page2.html
Doubt
Submit and process form  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Doubt
load next page after submitting  how to submit the details and how to go the next page after submitting.please clarify my doubt I don't know how to submit details.   1)page1.html: <html> <form type=get action
Struts Login Validation. In This code setter of login page is called only one time again it doesnt call it. Why..?
Struts Login Validation. In This code setter of login page is called only one...="com.credentek.recon.sms.action.IndexAction" method="login"> <...;action name="login" class="com.credentek.recon.sms.action.LoginAction">
login
login  How to create login page in jsp
login
login  How to create login page in jsp
login
login  login page display an error showing failure to login even when the correct information is entered
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution
JSF Validation In Login Application
:view> <html> <head><title>JSF Simple Login Example<...;td><h:outputText value="Enter Login ID: " /></td> <... for the resultforfail.jsp file: Login Failed! Here is the code
login
login  i want to now how i can write code for form login incolude user and password in Jcreator 4.50   Hello Friend, Visit HereADS_TO_REPLACE_1 Thanks
login
java.awt.event.*; class Login { JButton SUBMIT; JLabel label1,label2; final JTextField text1,text2; Login() { final JFrame f=new JFrame("Login Form...(); ResultSet rs=st.executeQuery("select * from login where username='"+value1
login
login  how to create login page in jsp   Here is a jsp code that creates the login page and check whether the user is valid or not. 1...;tr><td></td><td><input type="submit" value="Login">
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
validation
validation  validation
JSP Login Form with MySQL Database Connection and back end validation
Here we have created a simple login form using MySQL Database Connection and back end validation. We have also added a video tutorial of the program... database and matched with the input value given through the login form. Example
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
doubt on DAO's
doubt on DAO's  hai frnds.... can anyoneexplain about how to integrate struts with hibernate,any predifined plugin is available or we need to create our own plugin????? and please help me. how to use dao s while integrating
doubt
doubt
doubt
Doubt
DOUBT
doubt
doubt
validation
validation  How to validate username and password in a login screen
validation
validation  we are doing payroll system project in java.So pls provide the complete validation code for employee master form
PHP SQL Login Script
PHP SQL Login Script This Application illustrates how to create a php validation script for login application. In this example we create a login application where we put all php script for validation. In this application whether user
validation.....
validation.....  hi.......... thanks for ur reply for validation code. but i want a very simple code in java swings where user is allowed to enter only numerical values in textbox , if he enters string values then it should
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
java beginners doubt!
java beginners doubt!  How to write clone()in java strings
validation
Validation method valid the in put. otherwise call the javascript onsubmit to check... code.Ok if you use struts then you can use Validation method valid the in put
Validation
); JLabel label=new JLabel("JTable validation Example",JLabel.CENTER); JPanel panel=new JPanel(); panel.add(scroll); JFrame frame=new JFrame("JTable validation

Ads