JSP entered name and password is valid

JSP entered name and password is valid

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..........

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
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
Advertisements
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
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
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
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
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 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
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
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
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
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>
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
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
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
jQuery password validation
) or  unequal  password type entered. With the help of this password...;password_again" name="password_again" />ADS...jQuery password Validation : jQuery "equalTo: "#password" "
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.  ADS_TO_REPLACE_1 The code
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
jsp
JSP entered name and password is valid  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
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
file upload and insert name into database - JSP-Servlet
file upload and insert name into database  Hi, I just joined as a fresher and was given task to upload a file and insert its name into database. The max size of the file can be 1mb. Along with the file name, there are other 2
Visitor IP Address and Host Name using jsp
Visitor IP Address and Host Name using jsp  I have created one jsp page and i want to display the ip address of the visitor in my page. I used the following code to get the ip address: String ip=request.getRemoteAddr(); But i am
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>
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
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
Password
Password  make a program which ask ask the username and password * in this format. in C language
Remote System OS name in JAVA - JSP-Servlet
Remote System OS name in JAVA  I need to print the different os names of the all computers in my local network. I know that with System.getProperty("os.name"), I get the os name of my computer but for the other computers, I have
Name Display in alert box - JSP-Servlet
Name Display in alert box  Dear Sir, Please any one help me...(?username?).focus( ); } User Name...?, ?no-cache?); if(isExist){ response.getWriter().write(?User Name exists. Please
Why <servlet-name> use in web.xml - JSP-Servlet
;web.xml > tag <servlet-name> tag specifies the name of the servlet
password protected zip file creation exmpale coded neaded - JSP-Servlet
password protected zip file creation exmpale coded neaded  am able to create a zip file and able to read the file but password protection need please help
Difference between class,name,id attributes in each JSP tag
Difference between class,name,id attributes in each JSP tag  Can i know the difference between class,name,id attributes in each JSP tags.................. These 3 are only used for reference ..... And what are the differernces
jsp
jsp  how to create a table in oracle using jsp and the table name is entered in text feild of jsp page
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
Image name,image path into database and image into folder using jsp
Image name,image path into database and image into folder using jsp  How to insert image path and image name into oracle database and image into folder using jsp
how to take input table name in jsp to create table in mysql?
how to take input table name in jsp to create table in mysql?  how to take input table name in jsp to create table in mysql?   Hello Friend...; <form method="post"> Enter Table Name:<input type="text" name="table
ModuleNotFoundError: No module named 'is-valid'
ModuleNotFoundError: No module named 'is-valid'  Hi, My Python... 'is-valid' How to remove the ModuleNotFoundError: No module named 'is-valid... to install padas library. You can install is-valid python with following
ModuleNotFoundError: No module named 'is-valid'
ModuleNotFoundError: No module named 'is-valid'  Hi, My Python... 'is-valid' How to remove the ModuleNotFoundError: No module named 'is-valid... to install padas library. You can install is-valid python with following
ModuleNotFoundError: No module named 'VaLID'
ModuleNotFoundError: No module named 'VaLID'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'VaLID' How to remove the ModuleNotFoundError: No module named 'VaLID'
ModuleNotFoundError: No module named 'VaLID'
ModuleNotFoundError: No module named 'VaLID'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'VaLID' How to remove the ModuleNotFoundError: No module named 'VaLID'
ModuleNotFoundError: No module named 'is-valid'
ModuleNotFoundError: No module named 'is-valid'  Hi, My Python... 'is-valid' How to remove the ModuleNotFoundError: No module named 'is-valid... to install padas library. You can install is-valid python with following
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file... form like Emp name, Emp id, city, address and one employee profile image(upload
pass a variable(friends name) through a hyperlink in to another jsp.
pass a variable(friends name) through a hyperlink in to another jsp.  hi friends, i am developing a site in jsp. i have some problem,plz tell me the solution. problem: in the welcome page where friends name is show i write
pass a variable(friends name) through a hyperlink in to another jsp.
pass a variable(friends name) through a hyperlink in to another jsp.  hi friends, i am developing a site in jsp. i have some problem,plz tell me the solution. problem: in the welcome page where friends name is show i write
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

Ads