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



Home Answers Viewqa JSP-Servlet simple code to login user & authenticate it from database mysql
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Prateek Mishra
simple code to login user & authenticate it from database mysql
2 Answer(s)      3 years and 2 months ago
Posted in : JSP-Servlet


Sir,

I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database.

please tell me the code for it.

Thanks,,


Advertisement
View Answers

July 22, 2011 at 12:46 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="Login"></td></tr>
<tr><td></td><td><a href="register.jsp">Register Here</a></td></tr>
</table>
</form>
</html>

2)check.jsp:

<%@page import="java.sql.*"%>
<%
try{
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");
          }
        }
    catch(Exception e){
    System.out.println(e);
}
%>


July 22, 2011 at 12:47 PM


Please go through the following link:

JSP Login Application



Related Tutorials/Questions & Answers:
simple code to login user & authenticate it from database mysql
simple code to login user & authenticate it from database mysql  Sir, I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database. please tell me the code for it. Thanks
How to view database for user when they login in netbeans and mysql?
How to view database for user when they login in netbeans and mysql?  I create a web page where when user login they have to fill in a form, after... but it come out with all the other user information too. I'm using netbeans and mysql
Advertisements
how to retreive data from database of a particular user after login
how to retreive data from database of a particular user after login  ......please help in display details of particular student after he login ...i want to display the details of only current user who logged
how to retreive data from database of a particular user after login
how to retreive data from database of a particular user after login  ... the user information.. now their is a login and registration page for newuser. after the user has filled the form he should go to the welcome page where he
simple code for XML database in JS
simple code for XML database in JS  Sir , i want a code in javascript for XML database to store details (username and password entered by user during registration process (login process)). please send me a code . Thank you
Insert Image into Mysql Database through Simple Java Code
Insert Image into Mysql Database through Simple Java Code... simple java code that how save image into mysql database. Before running this java code you need to create data base and table to save image in same database
Servlet to authenticate user
from the database then client will be entered with authenticate user and password... Servlet to Authenticate User     ...; String url="jdbc:mysql://localhost/jsp?user=root&password=root
Login Authentication in JSP
from the database using MySQL and we are forwarding this servlet data...; For getting values from database we are using MySQL database and connecting... Use of Select Box to show the data from database   
java code for registration and login pages, mysql as a bankend.
java code for registration and login pages, mysql as a bankend.  please send me the java code for registration and login pages and to store the data in mysql
login application
Example Login Authentication using Bean and Servlet In JSP simple code to login user & authenticate it from database mysql Project of a web application...login application  how to create login application ?   Hi
login page using jsp servlrt with mysql database?
login page using jsp servlrt with mysql database?  Description: example:total users are 3.each use have username and password save in mysql database table login. After successfully login user1 see only index page,if user2 login
code for user registration page and login page of emails using jsp
code for user registration page and login page of emails using jsp  hiiiiiii please send me the code for user registration page and login page of email using jsp and servlets and also code for database connectivity to oracle
Spring 3 MVC Login Form Example with Database MySql
Spring 3 MVC Login Form Example with Database MySql  Sir i have checked your project of Spring 3 MVC Login Form Example But Sir Not able to do It with database Mysql. Can you Provide code for login with database. Thanks
Developing Login Action Class
for login action class and database code for validating the user against database... the user id and password from the login form and checks the login id... process. Get the login information from the user Developing Login Action Class
download code from database
download code from database  how to download files from database
Can anybody help me with this simple MySql code
Can anybody help me with this simple MySql code  select c.countryid, r.bp, r.sp, c.country, t.timee from rate as r, countryloc as c, todaysrate as t where r.countryid=t.countryid and t.countryid=c.country this is waht i gt whn
jsp page to add the user to mysql database
jsp page to add the user to mysql database  adduser.jsp: <...;title>Add User</title> </head> <form name="user" action...;tr> <td>User Name</td> <td><input type
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
data retrival from database throw simple jsp..
data retrival from database throw simple jsp..  We can retrieve the the data from data base simple jsp page: Jsp Page:retrive.jsp <...; Statement stmt = null; String Query="SELECT * FROM STUD"; try
Simple Login(JSF)
Simple Login(JSF)  I have tried to run the Simple Login code provided using netbeans. It gives me error. CAn I run it using netbeans or need to config anything in order to run the prog
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
Fetch user records from a table in database
Fetch user records from a table in database  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database.... Apache Tomcat/6.0.29  We have used MySQl database. 1)page.jsp: <
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... code retrieves the employee name in the dropdown. When the user selects any name
Submit comments in database when user clicks on submit button
create a database named "usermaster" in MySql and table named "user... Submit comments in database when user clicks on submit button... to show how to submit comments from a jsp page and insert it to the MySql
Retrieve image from mysql database through jsp
to retrieve image from mysql database through jsp code. First create a database... Retrieve image from mysql database through jsp... will be retrieved from database on the basis of  'id' field of the table. So code
@WebServlet Login and Logout Example
simple example which will demonstrate how you can create a login page, how can you authenticate them at the time of login, and finally logged out them in servlet... sql= "SELECT name FROM login WHERE name = '"+name+"'
How to hide HTML code from user? - Security
How to hide HTML code from user?  Hi All, I am trying to provide security to my web application. To achieve this I want to restrict user from... reconstruct your page as well from the code. Look up javascript obfuscation
JSP Login Form with MySQL Database Connection and back end validation
Here we have created a simple login form using MySQL Database Connection... a simple login logout example using JSP. When a user inputs information... to create JSP Login form backed with MySQL database: The following image
Repairing mysql database from command line
Repairing mysql database from command line  Hi, Can anyone tell me the process for repairing mysql database from command line? Thanks
User LogIn According to Role
User LogIn According to Role  User login According to role but output will be always displayed in a single page.. but content will change according role
 

 

 

DMCA.com