Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners JSP entered name and password is valid
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


deepti mishra
JSP entered name and password is valid
1 Answer(s)      2 years and 7 months ago
Posted in : Java Beginners


HII Im developing a login page using jsp and eclipse,there are two fields username and password,I want to know that how can i check that thw entered name and password is valid,how can i check that from database,plz help me..... Plz send me the codes. Im new in this field..........


Advertisement
View Answers

February 3, 2012 at 12: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="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:
"The folder name is not valid" netbeans
"The folder name is not valid" netbeans  "The folder name is not valid" while crating a jsp,html or any page in netbeans
validating username and password in servlet and redirect to login page with error message if not valid
and password in my servlet against database and if not valid want to display error message saying "Invalid username and password" in my login page. please help...validating username and password in servlet and redirect to login page
Advertisements
validating credentials and displaying error message in login .jsp if not valid
validating credentials and displaying error message in login .jsp if not valid  hi, i want to validate user name and password against my database table if not valid i have to display error message in my login page.how to do
change password - JSP-Servlet
on submit button. after that it should first check that current password entered... then new password must be set into the table masterdb. if the entered password is not in the table masterdb it must show a message that password is not valid
JSP code for forget password
JSP code for forget password  I need forget password JSP code.. example http://www.roseindia.net/users/forgotpassword.html
forgot password code in jsp
forgot password code in jsp  forgot password code in jsp   Please visit the following link: http://www.roseindia.net/jsf/richfaces
Encrypt Password with JSP - JSP-Servlet
to ask you how to make encrypt password with JSP servlet. For example I have... Friend, Try the following code: 1)form.jsp: User Name Password Confirm Password Name Phone Contact 2)encrypt.jsp
Change Password - JSP-Servlet
Change Password  Hi all, Please kindly help me with jsp code and explanations to enable me write a change password program. This program will connect to mssql database 2000. Thanks
Decrypt an encrypted password in JSP
Decrypt an encrypted password in JSP   How to decrypt an encrypted password and store in database ? Her is my code that i have done for encryption..."); > String > pass=request.getParameter("password"); > String > cpass
Password History - JSP-Servlet
Password History  I am using servlets and in my application i want to maintain password history.It means on password change My application should check previous 5 password so that new password can't be same to 5 old password
How to store data entered by User in JSP page in XML file
How to store data entered by User in JSP page in XML file  How to store data entered by user in JSP page to be saved in XML file.On clicking submit...   JSP store data entered by user into XML file 1)form.jsp: <html>
To Retain the values entered in the text box after submit in jsp page
To Retain the values entered in the text box after submit in jsp page   i am working on a jsp pge which has many text boxes and one dynamic drop... given all those. Now my problem is how can i retain those values entered in box
how to change password into one jsp to another jsp
how to change password into one jsp to another jsp  i have two jsps in one jsp i give one password and confirm password, in another jsp i want change my password compare with 1st jsp how to write code please give me answer?  
Change Password Code in JSP
Change Password Code in JSP In this example we will see how to change password... or not. In the new password, it matches the password entered in the first field with the password entered in the second field and if both of them matches, it saves
jQuery password validation
) or  unequal  password type entered. With the help of this password... class="left" id="password_again" name...jQuery password Validation : jQuery "equalTo: "#password" "
Send forgot Password through mail - JSP-Servlet
Send forgot Password through mail   hello every one I am designing a admin login page where i am validating the password through file(Example if user Name is Sreenivas and types sree as password i check a file where i
Password Controls
determines whether the password entered by the user is correct or not. This whole process is controlled on the server side. Once the password is entered by the user... the password entered by the user is correct or not.   The code of the program
Name Displaying - JSP-Servlet
Name Displaying  Dear Sir, Please any one help me......... when i enter some value in text that value is already in database dispaly the alert...( ); } User Name
code for password strength using jsp-servlet
code for password strength using jsp-servlet  hi.............. plz help me to give code for password strength using jsp-servlet for implementation in my project as soon as possible because i want to show this functionality in my
change password servlets - JSP-Interview Questions
change password servlets  hi all, i need the codes to create a change password servlet.  Hi, I dont have the time to write the code. But i... a link for change the password page in that page there should be a three text box
Password
Password  make a program which ask ask the username and password * in this format. in C language
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page  I have made a form in JSP having emp id... by user to be stored in xml file.here you have entered data in JSP file
Valid Statment Checker
Valid Statment Checker  Write a program about valid statement checker. The valid statement checker is a program that checks the validity... = x+y Output:INVALID STATEMENT Input a statement: y=(x+y); Output: VALID
validation error value is not valid
validation error value is not valid  How to recognize and throw error like "validation error value is not valid
Duplicate name in Manifest - JSP-Servlet
Duplicate name in Manifest   Hello, I don't have the classpath variable in the system variables instead I have Path variable. In that path I... WARNING: Duplicate name in Manifest: Depends-On. Ensure that the manifest does
can any one give the frogort password code using jsp,
can any one give the frogort password code using jsp,  plz give the code for frogot password
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
a jsp file which contains a textbox, name issuedescription. when user types...how to retreive values from MS Access Database based on the values entered in textbox values in jsp file  Hi am new to java. i need to create
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... type="password" name="pass"></td></tr> <tr><td>Select
how to check username & password from database using jsp
. in my oracle10G database already contain table name admin which has name, password. name is amit and password is ddave. so hw could i check whether the username...how to check username & password from database using jsp  Hello, I
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct...  my project has login in whic i should select the company name...;input type="password" name="pass"></td></tr> <tr><td>
jsp login code when username , password and dropdown box value is correct...
jsp login code when username , password and dropdown box value is correct... Password!"); return false; } return true; } </script> <form name="form..." name="user"></td></tr> <tr><td>Password:</td>
Advertisements
 

 

 

DMCA.com