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



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

Have Programming Question? Ask it here!
 
 
 


deepti mishra
JSP entered name and password is valid
1 Answer(s)      2 years and 6 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
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
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
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
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
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
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... Password!"); return false; } return true; } </script> <form name="form..." name="user"></td></tr> <tr><td>Password:</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...  my project has login in whic i should select the company name...;input type="password" name="pass"></td></tr> <tr><td>
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
to store data entered in html page
use two forms for it 1)for user name,password, submit button 2)for text field,reset and submit botton in form 1 after entering username and password by clicking...to store data entered in html page  i want to a job site
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
Name
Name  make a program that take a input from user in alphabet and show all the name of that character E.g User give character "B". The program shows all the human names which starts from B.   Java show all names
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
Username password
that checks whether the username and password is valid or not. If the user...("")) { JOptionPane.showMessageDialog(null,"Enter login name or password","Error... with the validation, so that if the username and password match it will continue
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
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
validating a form before data is entered.
validating a form before data is entered.  How can I avoid validating a form before data is entered
forget password
forget password  can i get coding for forgot password in jsp, need using javamail also cannot.. what should i do?? Thx
Password encryption and decryption
;/td><td><input type="password" name="pass"></td></tr>... name=request.getParameter("name"); String password=request.getParameter("pass... INTO user(name,password,address,telno) VALUES(?,?,?,?)"); ps.setString(1,name
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
line number in a file of entered string
line number in a file of entered string  when i entered string from console , it should show line number in a file of that string
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...="post"> Enter Table Name:<input type="text" name="table"><input type
Forget Password
Forget Password  How i get my forget password through mail?   Please visit the following links: http://www.roseindia.net/jsf/richfaces/ http://www.roseindia.net/jsf/richfaces/developing-jsp-files.shtml
 

 

 

DMCA.com