Home Answers Viewqa Java-Beginners Log In Form Validations

 
 


shweta
Log In Form Validations
1 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners

Good Morning
Sir ,I have Created Log in Form with Databse Connectivity and i have took two JTextFields 1)USERNAME
2)password if two Jtextfields are blanks i want to show msg blank Username and Password ,
How I can Do That ,plz Help Me Sir.
View Answers

April 8, 2010 at 11:42 AM


Hi Friend,

Try the following code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class LoginDemo{
JButton SUBMIT;
JFrame f;
JLabel label1,label2;
final JTextField text1;
final JPasswordField text2;
LoginDemo(){
f=new JFrame();
f.getContentPane().setLayout(null);
label1 = new JLabel();
label1.setText("UserName:");
label1.setBounds(400,50,100,20);
text1 = new JTextField(25);
text1.setBounds(500,50,100,20);
label2 = new JLabel();
label2.setText("Password:");
label2.setBounds(400,80,100,20);
text2 = new JPasswordField(25);
text2.setBounds(500,80,100,20);
SUBMIT=new JButton("Login");
SUBMIT.setBounds(500,110,100,20);

f.add(label1);
f.add(text1);
f.add(label2);
f.add(text2);
f.add(SUBMIT);
f.setSize(1024,768);
f.setVisible(true);
SUBMIT.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
String user1="";
String pass1="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM login where username='"+value1+"' && password='"+value2+"'");
while (res.next()) {
user1 = res.getString("username");
pass1 = res.getString("password");
}
if(!value1.equals(user1) && !value2.equals(pass1)) {
JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
else if(value1.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Username","Blank",JOptionPane.ERROR_MESSAGE);
}
else if(value2.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Password","Blank",JOptionPane.ERROR_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"Welcome");
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
});

}
public static void main(String arg[]) {
LoginDemo frame=new LoginDemo();
}
}

Thanks









Related Pages:
Log In Form Validations - Java Beginners
Log In Form Validations  Good Morning Sir ,I have Created Log in Form with Databse Connectivity and i have took two JTextFields 1)USERNAME 2)password if two Jtextfields are blanks i want to show msg blank Username
Validations
the reason.   Here is an example that validates some fields of html form. <html> <h2>Form Validation</h2> <script language... } </script> <form name="form" method="post" onSubmit
log in
log in  sir i designed one login.jsp page with one form, username,login,and one submit button .if i enter username and password its been verify the mydatabase in in table in the field of username and password while it s correct
validations - Struts
validations  log in page with validations user name must be special character and one number and remining is alphabetes in struts
Struts validations
the given input from the form. i.e, the given username and password have to be compared
java validations
;form name="retailer" action="RetController" onsubmit="return validateForm();">...; <!-- start id-form --> <table border="0" cellpadding="0" cellspacing="0" id="id-form"> <tr> <
log in page
log in page  hi all i want to create a login page in jsp which should...', 'application/x-www-form-urlencoded'); xmlHttp.onreadystatechange = function...;Center> <form name="f1" onsubmit="return call_login();"> <table
failure to log in
failure to log in  <blockquote> <p>Blockquote</p> </blockquote> <p>&lt;%@page contentType="text/html"%>...; &lt;form name="LoginForm" id="LoginForm" method=post Action="login.jsp"&
listbox and textbox validations
listbox and textbox validations  hi, any one please tell me how to set validations for listbox and textboxes using bean classes? thank you...-registration-form-using-jsp.shtml
validations
validations  How to get All Client and server side validations in spring using jsp   Please visit the following link: Spring Validation Example
Im not getting validations - Struts
in s-c.xml But Im unable to get validations This is my validation.xml file... ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request...{ DynaActionForm studForm = (DynaActionForm)form; ActionMessages errors = new
Javascript validations problem
Javascript validations problem  i have attached two jsp files 1.sports1.jsp and sports.jsp files Here when i run my sports.jsp file my validation...(); } </script> </head> <body> <FORM name="myform
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you...-registration-form-using-jsp.shtml
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I....), how to manipulate date validations through JavaScript or Ajax? Thanks...;TITLE>Form Validation</TITLE> <% String messageFormField1="Please enter
Context Log Example Using Servlet
Context Log Example Using Servlet  ... of Context Log in servlet. Context Log is used to write specified message to server log file when servlet is called. In the following JSP page (message.jsp) we
Struts: validations code to support 2 date foramats - Struts
Struts: validations code to support 2 date foramats  What is the code in validation.xml to support 2 date formats (DD-MM-YYYY & DD/MM/YYYY ) in form. (I'm using struts 1.3
validations in javascript
validations in javascript  How do you check validations in javascript
Validations using Struts 2 Annotations
. Develop Login Form The GUI of the application consists of login form (log-in.jsp) and success message page (loginsuccess.jsp). The log-in.jsp...Validations using Struts 2 Annotations     
Validations using Struts 2 Annotations
Validations using Struts 2 Annotations     .... Develop Login Form The GUI of the application consists of login form (log-in.jsp) and success message page (loginsuccess.jsp) . The log
Log out from website - JSP-Servlet
Log out from website  what is the code to how to log out from...="100%"> <form method="POST" action="... a user to log in and log out from the application using JSPJSP Tutorialshttp
Log-in Valdidation
Log-in Valdidation  how to create login validation in jsp
log out
log out  how do i create a log out on a project without it exiting system so it does not reload again
how to validate javascriptcode n i am attaching file give validations
) noBack();" onunload=""> <form action="PrepaidGSMVerification...:20px;">PAN/Form 60/61 Signed by Customer</td>
how to validate javascriptcode n i am attaching file give validations
) noBack();" onunload=""> <form action="PrepaidGSMVerification...:20px;">PAN/Form 60/61 Signed by Customer</td>
how to validate javascriptcode n i am attaching file give validations
) noBack();" onunload=""> <form action="PrepaidGSMVerification...:20px;">PAN/Form 60/61 Signed by Customer</td>
how to validate javascriptcode n i am attaching file give validations
) noBack();" onunload=""> <form action="PrepaidGSMVerification...:20px;">PAN/Form 60/61 Signed by Customer</td>
how to validate javascriptcode n i am attaching file give validations
) noBack();" onunload=""> <form action="PrepaidGSMVerification...:20px;">PAN/Form 60/61 Signed by Customer</td>
log 4j
log 4j  what is log4j? can you give me clear information about log4j?   Please go through the following link: log4j Tutorials
spring form validation
spring form validation  how can we validate a web form using spring, try to give an example of the form containing some fields and their validations,ASAP......   Please visit the following link: Spring form validation
error log
error log  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details-------------- Table
Struts Validations - Framework
Struts Validations  What is the server-side validations exactly? give me on example
Writing Log Records to a Log File
Writing Log Records to a Log File       This section demonstrates for writing log records to a log file. Logger provides different types of level like: warning, info
Custom Validations - Struts
Custom Validations  Hi, I am trying to do the custom validations in struts 1.1.That is how can we plug in our own custom validations into Validator ? Can anybody tell me how to do this with a sample example. Thanks
Multiple Validations on jTestFields
Multiple Validations on jTestFields  Hi, I am working on an window application in which I have to validate the data of text fields, like if textbox1... then it should check whether it is valid or not. Unless all the validations
struts validations - Struts
struts validations  hi friends i an getting an error in tomcat while running the application in struts validations the error in server as validation disabled plz give me reply as soon as possible.  Hi friend
validations in struts - Struts
validations in struts  hi friends plz give me the solution its urgent I an getting an error in tomcat while running the application in struts validations the error in server as "validation disabled" plz give me reply as soon
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
user log in according to their role
user log in according to their role  i want a jsp code for different users log in to different pages according to their role.example normal user and administrator. normal user for user page and administrator for admin page
error log and send Database
error log and send Database  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details
Not retriving the validations from validation.xml - Struts
Not retriving the validations from validation.xml  I have create the file called register.jsp    LoginID: Password: when i
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
Error in log file
Error in log file  Hi, I AM using Apache tomcat 6.0.16 server... of executing project i get following errors in "Apache Tomcat 6.0.16 log". Apr 17, 2011 11:57:57 AM org.apache.catalina.core.ApplicationContext log INFO: Marking
form
form   Can I prevent a form from being submitted again
JSP cannot log to FileAppender - Log4J
JSP cannot log to FileAppender  Hi, Thank you for your attention... method. But when the LogClass is called from jsp file, no log file is created... ----------------------------------------------------------------------------- ### direct log messages to stdout
Dealing with negative lat/log numbers
Dealing with negative lat/log numbers  I need to run a script that will return cities that match within a certain range of the latitude and longitude. We are trying to check to make sure what we return for lat/log matches close