how to create a login page and registration page?

Ads
 

how to create a login page and registration page?

hellow, pls tell me the code for how we can create a login page and registration page and how we can store the info in database.only in advance java as jsp.

View Answers

May 30, 2011 at 10:53 AM

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">New User<a></td></tr>

</table>
</form>
</html>

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");
          }
%>

3)register.jsp:

<html>

<form name="form" method="post" action="insertdata.jsp">
<table>
<tr><td>Enter First Name</td><td><input type="text" name="fname"></td></tr>
<tr><td>Enter Last Name</td><td><input type="text" name="lname"></td></tr>
<tr><td>Enter Username</td><td><input type="text" name="uname"></td></tr>
<tr><td>Enter Pasword</td><td><input type="password" name="pass"></td></tr>
<tr><td>Enter Address</td><td><input type="text" name="address"></td></tr>
<tr><td>Enter City</td><td><input type="text" name="city"></td></tr>
<tr><td></td><td><input type="submit" value="Add" name="button"></td></tr>
</table>
</form>
</html>

May 30, 2011 at 10:54 AM

continue....

4)insertdata.jsp:

<%@page import="java.sql.*,java.util.*"%>
<table>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String uname=request.getParameter("uname");
String pass=request.getParameter("pass");
String address=request.getParameter("address");
String city=request.getParameter("city");
System.out.println(fname+lname+uname+pass+address+city);
        try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
        Statement st=con.createStatement();
        int i=st.executeUpdate("insert into login(firstname,lastname,username,password,address,city) values('"+fname+"','"+lname+"','"+uname+"','"+pass+"','"+address+"','"+city+"')");

        out.println("Data is successfully inserted into database.");

                    con.close();

        }
        catch(Exception e){
        System.out.println(e);
        }
        %>
        </table>

Ads









Related Tutorials/Questions & Answers:
how to create a login page and registration page?
How to Create Login/ Registration Form using PHP and MYSQL
Advertisements
java code for registration and login pages, mysql as a bankend.
how to create session for login
how to create a user registration form in php
RichFaces: Login & Registration Application:
code for user registration page and login page of emails using jsp
How to make Struts Hibernate and Spring Based Login/Registration Application?
Login & Registration - JSP-Servlet
php create pages automatically
Login form and registration
How to retrieve kernal memory details(paged and non-paged ) using SIGAR API in java program
Login page
How to Create Student Registration Form with HTML Code?
Spring, Hibernate login and registration application
basic login and registration web page using jsp and servlet without using bean .....
create login page using data from text file
how to create a xml page
how to create web page on jsp?
login page in php
How to insert data into databse by JSP form registration page in netbeans
login page
to create registration form
Login Page
login page
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?
how to connect jsp with sql database by netbeans in a login page?
login page
How to create form in Swings
jsp login page

Ads