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



Home Answers Viewqa Java-Beginners JSP Login Page Question
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ankit Kumar
JSP Login Page Question
2 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


hey..i have a login page where different users first registered and then after they can login.
my question is how a user can see only his data after login where different users data are stored in database, plz...provide me answer its very urgent.


Advertisement
View Answers

June 5, 2012 at 12:35 PM


The given code accepts username and password to check whether the user is valid or not. If the user is valid, whole record of that particular user will get retrieved from the database and displayed it on the welcome page. Apart from this if user is not registered, then he or she can register himself first and then login.

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: 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 register where username='"+user+"' and password='"+pass+"'");
           int count=0;
           while(rs.next()){
           count++;
          }
          if(count>0){
           out.println("welcome "+user);
           %>
           <table>
            <tr><td>First Name:</td><td><input type="text" value="<%=rs.getString("firstname")%>"></td></tr>
            <tr><td>Last Name:</td><td><input type="text" value="<%=rs.getString("lastname")%>"></td></tr>
            <tr><td>User Name:</td><td><input type="text" value="<%=rs.getString("username")%>"></td></tr>
            <tr><td>Date Of Birth</td><td><input type="text" value="<%=rs.getString("dob")%>"></td></tr>
            <tr><td>Age:</td><td><input type="text" value="<%=rs.getInt("age")%>"></td></tr>
            <tr><td>Email</td><td><input type="text" value="<%=rs.getString("email")%>"></td></tr>
            <tr><td>Address:</td><td><input type="text" value="<%=rs.getString("address")%>"></td></tr>
            <tr><td>Country</td><td><input type="text" value="<%=rs.getString("country")%>"></td></tr>
            <tr><td>State:</td><td><input type="text" value="<%=rs.getString("state")%>"></td></tr>
            <tr><td>City</td><td><input type="text" value="<%=rs.getString("city")%>"></td></tr>
            <tr><td>Telephone No:</td><td><input type="text" value="<%=rs.getInt("telephone")%>"></td></tr>
            <tr><td>Mobile:</td><td><input type="text" value="<%=rs.getInt("mobile")%>"></td></tr>
           </table>
           <%
           }
          else{
           response.sendRedirect("login.jsp");
          }
        }
    catch(Exception e){
    System.out.println(e);
}
%>


June 5, 2012 at 12:36 PM


continue..

3)register.jsp:

<html>
<form method="post" action="insert.jsp">
<table>
<tr><td>First Name:</td><td><input type="text" name="fname"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lname"></td></tr>
<tr><td>User Name:</td><td><input type="text" name="uname"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="cpass"></td></tr>
<tr><td>Date Of Birth</td><td><input type="text" name="dob"></td></tr>
<tr><td>Age:</td><td><input type="text" name="age"></td></tr>
<tr><td>Email</td><td><input type="text" name="email"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address"></td></tr>
<tr><td>Country</td><td><input type="text" name="country"></td></tr>
<tr><td>State:</td><td><input type="text" name="state"></td></tr>
<tr><td>City</td><td><input type="text" name="city"></td></tr>
<tr><td>Telephone No:</td><td><input type="text" name="tno"></td></tr>
<tr><td>Mobile:</td><td><input type="text" name="mobile"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

4)insert.jsp:

<%@page import="java.sql.*,java.util.*"%>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String uname=request.getParameter("uname");
String pass=request.getParameter("pass");
String cpass=request.getParameter("cpass");
String dob=request.getParameter("dob");
int age=Integer.parseInt(request.getParameter("age"));
String email=request.getParameter("email");
String address=request.getParameter("address");
String country=request.getParameter("country");
String state=request.getParameter("state");
String city=request.getParameter("city");
int telephone=Integer.parseInt(request.getParameter("tno"));
int mobile=Integer.parseInt(request.getParameter("mobile"));
        try{
         Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
           Statement st=con.createStatement();
           int i=st.executeUpdate("insert into register(firstname,lastname,username,password,confirm_pass,dob,age,email,address,country,state,city,telephone,mobile) values('"+fname+"','"+lname+"','"+uname+"','"+pass+"','"+cpass+"','"+dob+"',"+age+",'"+email+"','"+address+"','"+country+"','"+state+"','"+city+"',"+telephone+","+mobile+")");
        out.println("Data is successfully inserted!");
        response.sendRedirect("login.jsp");
        }
        catch(Exception e){
        System.out.print(e);
        e.printStackTrace();
        }
        %>


Related Tutorials/Questions & Answers:
JSP Login Page Question
JSP Login Page Question  hey..i have a login page where different users first registered and then after they can login. my question is how a user can see only his data after login where different users data are stored
jsp login page
jsp login page  hi tell me how to create a login page using jsp and servlet and not using bean... please tell how to create a database in sql server... please tell with code
Advertisements
JSP LOGIN Page
JSP LOGIN Page  sir....i have two user types usercategory and user and both user have userid and password in two different table and now i am making login page for which i have to retrieve usertype,userid and password from two
jsp login page
jsp login page  Hi All, can any one tell me how to create Login page using JSP and Beans. A simple log in page. Please reply ASAP. Thanx, am2085   Hello Friend, Please visit the following link: JSP Login Using
login page with mysql using jsp
login page with mysql using jsp  pls i need a sample of login page to check username and password in mysql database. thanks
login page using jsp servlrt with mysql database?
login page using jsp servlrt with mysql database?  Description... table login. After successfully login user1 see only index page,if user2 login then he see only visiter page and so on. please gine me any suggession. Thanks
Redirect to same jsp page on successful login
Redirect to same jsp page on successful login  Hi, I have an application where on successful login, the redirect should happen to same page... from the database. I am unable to create the session for the same login page
login page
login page  code for login page
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
login page
login page  pls say how to create a login page in jsp and mysql using netbaens   Hi Friend, Please visit the following links: http://roseindia.net/jsf/netbeans/index.shtml http://roseindia.net/jsp/loginbean.shtml
Login page
Login page  how to create Login page in java
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
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
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
admin login control page - JSP-Servlet
admin login control page  how to encrypted password by using jsp... adminPage.jsp?  JSP Example code for encrypted passwordJSP Encrypted Password Example CodeadminPage.jsp<html> <title>Admin login
Login Page
Login Page  Can anyone tell me the steps to create a login page in myeclipse 7.0 and validating it with login database in db2 9.7 ??? Please tell me
Direct jsp coding for gmail login page and to open mail
Direct jsp coding for gmail login page and to open mail  DEAR SIR, i'm urgently in need of jsp coding to create login page of gmail and to open mail
login page
login page  hi i'm trying to create login page using jsp. i get... the program. Following are my programs... 1.index.jsp <%@page contentType="text/html" pageEncoding="UTF-8"%> JSP Page
login page
login page  How to login as different user in php
LOGIN PAGE
LOGIN PAGE  A java program with "login" as title,menus added, and a text field asking for firstname, lastname, and displaying current date and time
using ajax and jsp (struts) to login and remain on same page.
using ajax and jsp (struts) to login and remain on same page.  I am a fresher... I can forward my login page to success page using struts, but I want to remain on same login page and just want to display loggers name ... I don't
coding for login page
coding for login page  coding for login page
login page in php
login page in php  How to create a login page in php
login page - Java Beginners
login page  I have one login page in jsp that is login.jsp. Now i have validate user from database by another page validate.jsp. but if the user feeded wrong information then i want to print error massege on the first page
JSP LOGIN
JSP LOGIN  sir....i have two user types usercategory and user and both user have userid and password in two different table and now i am making login page for which i have to retrieve usertype,userid and password from two
login for different user in the same page
login for different user in the same page  how can i do the login for different user in the same page throug jsp
login page code in asp.net
login page code in asp.net  i need front end and backend code for login page in vb asp.net using sql server....having code for submit button
SSL for login page
SSL for login page  I am trying to apply ssl cert to login page only. Does anyone know how to do this on a tomcat web server
login page error
login page error  How to configure in to config.xml .iam takin to one login form in that form action="/login" .when iam deployee the project... this request." please suggest me.   if your login page is prepared
login in jsp
and otherwise show the failed message.   JSP Login Form 1)login.jsp: <html>...login in jsp  i need code for login which is verify the registeration...;</font></label> <% } %> 2)check.jsp: <%@page import
html login page with ajax
html login page with ajax  hi all... i want to create a login page...... thanks in advance   Here is a jsp example that accepts username...=="yes"){ alert("Welcome User"); }else{ alert("Invalid Login! Please try again
 

 

 

DMCA.com