form with username and password

form with username and password

i want to design one form with username and password,login...if i click login the jsp check the database table with all username and password field if its find means the link goes to my personalinfo.html...i am confused how to check enterted username with all username fields and how to transfer link to another html if i find..ple guide me

View Answers

March 29, 2012 at 4:18 PM

1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  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"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></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("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+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");
          }
%>

March 29, 2012 at 4:19 PM

1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="http://localhost:8080/examples/Login" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)Login.java:

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Login extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { 

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try{
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            out.println("welcome "+user);
          }
          else
          {
                       response.sendRedirect("/examples/jsp/login.jsp");
          }
    }
    catch (Exception e) {
    e.printStackTrace();
    }
}
}









Related Tutorials/Questions & Answers:
Create an HTML form login.html that accepts the username and password
Create an HTML form login.html that accepts the username and password   Create an HTML form login.html that accepts the username and password and submits to login.java servlet. Verify credentials and on success, set the username
Username password
with the validation, so that if the username and password match it will continue... that checks whether the username and password is valid or not. If the user...=st.executeQuery("select * from login where username='"+value1+"' and password='"+value2
Advertisements
username and password in servlet
username and password in servlet  i'm usng eclipse luna(java programming) Sevlet and apache tomcat8.0 i need to do a login page then after login... in: Please Enter Your User Name: Please Enter Your Password
encrypt the username and password using PHP
encrypt the username and password using PHP  How can we encrypt the username and password using PHP?   Hi friends, You can use the MySQL PASSWORD() function to encrypt username and password. For example, INSERT
validating username and password from database
validating username and password from database  Hello sir, i am developing a login page. i want that when i fill data in text fields. it validate data from database. if enter data is match from database. page goes to next page
Developing Forgot Password Form
Developing Forgot Password Form   ... Form code for our application. Developing Forgot Password FormADS_TO_REPLACE_1   The forgot password form will be used, when user forgot their password
How can we encrypt the username and password using PHP?
How can we encrypt the username and password using PHP?  How can we encrypt the username and password using PHP
jsp login code ... when username , drop down box and password is correct
jsp login code ... when username , drop down box and password is correct  i need a jsp code for login.... when username password and dropdown box...; var password=document.form.pass.value; if(username==""){ alert("Enter Username
validating username and password in servlet and redirect to login page with error message if not valid
validating username and password in servlet and redirect to login page with error message if not valid  hi i want to validate my login page username... error message saying "Invalid username and password" in my login page. please help
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... in dropdown box.... so when i login i all the three username,password and dropdown box...=document.form.user.value; var password=document.form.pass.value; if(username==""){ alert("Enter
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... in dropdown box.... so when i login i all the three username,password and dropdown box...=document.form.user.value; var password=document.form.pass.value; if(username
how to check username & password from database using jsp
how to check username & password from database using jsp  Hello, I have created 1 html page which contain username, password & submit button.... name is amit and password is ddave. so hw could i check whether the username
to enter into a particular page only if the username,password and listbox value mtches
to enter into a particular page only if the username,password and listbox value... in to his page only if the username, password and the listbox value(user type) matches using "jsp".where the username,password,user type are stored in a single table
Java Read username, password and port from properties file
Java Read username, password and port from properties file In this section, you will come to know how to read username, password and port no from... username=root password=root port=3306 Here is the code:ADS
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  //this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
unable to validate username and password from ms acess database
unable to validate username and password from ms acess database  //this code is not working! please help me to find error. thanks. <%@ page import="java.sql.*" %> <% Connection con=null; String user
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
simple code to write an read and write the login detail to a xml file using javascript ( username and password )  pls can nyone give me a code to write and read the login details (username and password )into a xml file using
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
code to validate username password of gmail and procedures to establish jdbc connectivity to store unread mails and retreive it..
code to validate username password of gmail and procedures to establish jdbc..., 1)I am in need of code to establish username and password of gmail 2)code in jsp to validate the username and password of my gmail mentioned above
How to create the program in Java for getting the forgotten Password Form?
How to create the program in Java for getting the forgotten Password Form?  Hi, Our enterprise application requires the development of a form... the forgotten Password Form? Thanks   For this you should create a form
Password
Password  make a program which ask ask the username and password * in this format. in C language
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password)
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password)   myself muthu,am working as software trainee in reputed concern.our company gave one project to me.create
sir plz help in design a jsp page whichis as follow username [_____] select [__>]password [_____] after selection then onlypassword text box is visible
sir plz help in design a jsp page   sir plz help in design a jsp page which is as follow username [ _ ] select [ > ] password [ _ ] after selection then only password text box is visible
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password) 0 Answer(s)
create webpage with table sql database using netbeans 6.8 with struts complete tutorial.(include username and password) 0 Answer(s)  create webpage... username and password
how to genrate login id and password after submitting the sign up form?
how to genrate login id and password after submitting the sign up form?  i m working on a online voting project in that i have a user sign up form so i want 2 knw that after user submit all the details i that sign up form than
Swing login form example
text for username and password. We create one submit button and perform an action. We have used get method. get method has get value username and password. Then we create a condition that if "username" textField and "password
How to Display Username After Login in JSP
to display the Username and password after the successful login. In JSP... page in which username and password is created. So, when you submit the details the username and password will be displayed on the other page. Using
The password tag
In this section, you will learn about the password tag of the Spring form tag library
How to supress displaying username and password in Java Web Start 10.21.2.11 Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM
How to supress displaying username and password in Java Web Start 10.21.2.11... installed Java 1.7.21 from java 1.6. I am observing username and password (match... messages. Could you Please tell me how to suppress username and password from JNLP
Password Tag (Form Tag) Example
Password Tag (Form Tag) Example       In this section, we are going to describe the password tag. The password tag is a UI tag that renders an HTML input tag of type password. Add
windows username - JSP-Servlet
windows username  how to reset the password and username of windows using jsp
Login Form in Swing
to set the text for username and password. A button is created to perform an action... username and password , the class JOptionPane provides the MessageDialog to shows... Login Form in Swing      
change password
change password  how to change password in the login form.... by giving options to user like this old password, new password.. pls help
Username availabiltiy
Username availabiltiy  Can we check username availability on front end before submitting just with javascript and php not using jquery or ajax
MySQL Creating account and changing password
to create new password.  Mysql as the intended username and the group... again []: admin ... Name: username Password: xxxx...,username,password) values ("%","USERNAME",password("PASSWORD"));  
Change Password Code in JSP
in Changepassword.jsp form. If you will not enter value in password field than...Change Password Code in JSP In this example we will see how to change password code in jsp. First of all we have created a form where we have displayed
Encrypt Password with JSP - JSP-Servlet
Encrypt Password with JSP  Hi guys... I need you help.... I want to ask you how to make encrypt password with JSP servlet. For example I have form registration consists of: username, password, retype password, fullname, telp
form
form   Can I prevent a form from being submitted again
login-password - Java Beginners
login-password  complete code of login-password form then how...){ if(theForm.userid.value==""){ //Please enter username alert("Please enter User Name...; } if(theForm.password.value==""){ //please enter passward alert("Please enter Password
How to make Spring web Login form?
) private String password; public void setUserName(String userName..."); if (!loginForm.getUserName().equals(userName) || !loginForm.getPassword().equals(password..." and password="password" </FONT> <form:form action="loginform.html
Form handling
;/td> <td> <form:input path="username"/>...;b>Password:</b></td> <td><form:input path...Form handling  I created a spring project. I created a jsp
foget password
password form have three field that is userid ,security question and answer of those...foget password  i have make a login form and add three buttons.one is user login ,second is new user and third is forget password in java using
HTML Form Validation example
HTML Form Validation example  Can anyone guide me how to validate the user name and password field in HTML using simple or JavaScript Validation. Thanks in advance!   <form method="post" onsubmit="return
Forgot Password Action,Struts Forgot Password Action class
username=strPasswordEmail[2]; String subject="Your username & password... Please login to the web site with your username and password."; message... & password "; String message="Hi,"+username; message+="\n Your
servlet code to update password?
servlet code to update password?  Create a servlet page which helps the user to update his password. The user should give the username,old password,new password,confirm password. The updation is applicable only for valid

Ads