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



Home Answers Viewqa Java-Beginners JSP data after login where different users data are stored in database

Have Programming Question? Ask it here!
 
 
 


Ankit Kumar
JSP data after login where different users data are stored in database
2 Answer(s)      a year and 10 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 data after login where different users data are stored in database
JSP data after login where different users data are stored in database  hey..i have a login page where different users first registered... where different users data are stored in database,plz...provide me answer its
the last data entered into database is getting stored again after refreshing
the last data entered into database is getting stored again after refreshing  hey all i made a shout box using php and mysql but the last data... if the data is deleted from the database the last data entered is getting posted plz help
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  ... 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
how to retreive data from database of a particular user after login
how to retreive data from database of a particular user after login  sir am doing project in ASP.NET useful for my college that is placement portal...please help in display details of particular student after he login ...i want
Retriving data stored in database
Retriving data stored in database  Hi, How to retrive data from my sql database using Hibernate,Spring and tapestry please give me an example.I am new to this Hibernate and Spring
where are program instructions and data values stored
where are program instructions and data values stored  Where are program instructions and data values stored in Computer?   In Storage. Actually, whichever program and data we use in our computers are stored in Storage
callable statement,stored procedure for insert data and also for update data into oracle database using jsp
callable statement,stored procedure for insert data and also for update data into oracle database using jsp  iam a fresher newbie to softparsing i... procedure for inserting data into oracle database as bind variable and same
login data
the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance...login data   Hiiii Sir I am doing banking project on Asp.net i have
login data
the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance...login data  Hiiii Sir I am doing banking project on Asp.net i have
how to create alert message after data submitted into database
how to create alert message after data submitted into database  I want to create alert message box after data stored into database and redirect to another page, how to do
Retrieve data from databse using where in JSP
Retrieve data from databse using where in JSP  Hi, can somebody help me? I have a jsp page. in that i want to get data from the database where... help me. ALL DATABASE CONNECTIONS ARE OK. THE ERROR IS SHOWN IN "WHERE". IT SAYS
How to Restore The Lossed data in MYSQL database after the System is formatted
How to Restore The Lossed data in MYSQL database after the System is formatted  How to Restore The Lossed data in MYSQL database after the System is formatted
to read data stored in ArrayList - Struts
to read data stored in ArrayList  this is regarding struts2, i have create one ArrayList object and in that i have stored 4 User class objects taking them from database. Now i want to read the data of all 4 User objects from jsp
auto suggest where the data should come from database - Ajax
auto suggest where the data should come from database  auto suggest in (java script or ajax)where the data should come from one of the table in database thnks in advance MamthaDatta  Hi Friend, You can visit
automatically move next page when data fetched from database is stored in text field
automatically move next page when data fetched from database is stored in text field  hi I have php page where i have two text fields . The data are stored in database wherein when the in the first text field the data is already
jsp with excel sheet data uploading into database
jsp with excel sheet data uploading into database  how to upload data in excel sheet with jsp into oracle 10g database
how to display data from database in jsp
how to display data from database in jsp  how to display data from database in jsp
Insert Data in Table Using Stored Procedure
Insert Data in Table Using Stored Procedure        In this example we are inserting data into a table using stored procedure. Steps: 1.Create database: To create
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.
in a textbox. The data is stored in database.  The code for retrieving data from database into Drop Down List. <% DataSource data = new... for displaying quantity is below but its now working.I am new to jsp, so dont know how
data are not display in JSP from database - JSP-Servlet
data are not display in JSP from database   i want to finding some data through a SQL query from SQL server database to a JSP page based on some... of this jsp page. like.. School Result and three request parameters 'class', 'from
how to retrive data grom database in jsp pages.
how to retrive data grom database in jsp pages.  sir, i have problem to retrieve data from table of the database on the html web pages , so would... immediately. i want sample code of jsp to retrieving data from table of database to html
Object with different data types
Object with different data types  Hello, I need to build a "patient" object that can contain String "name", String "ID", double "weight" and Date "birthDate". Then that object is referenced to the linked list. I know how to use
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <..."; if(sdto.getPid()==null || !sdto.getPid().equals("")) { query=query+" "+"where pid...="false"%> The following details are stored in DB {pid} {pname} {price
how to insert data into database using jsp & retrive
how to insert data into database using jsp & retrive  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
Display Data from Database in JSP
, to show data from the database click on the link that calls another .jsp file named...;body> <h2>Data from the table 'stu_info' of database 'student'</h2..._to_database_query.jsp. Click on the link given in the first jsp page,that calls
displaying data retrieved from a database in a jsp page
displaying data retrieved from a database in a jsp page  the page should display username, emailid, telephone in addition to tthe tagline however... sql = "select billid, customerid, billdate, status from customerbills where
How to show data from database in textbox in jsp
How to show data from database in textbox in jsp   How to show data from database in textbox in jsp   Here is an example that retrieve the particular record from the database and display it in textbox using JSP. <
how to display data from jsp file into database
how to display data from jsp file into database  this is a jsp file...+",'"+email+"')"); out.println("Data is successfully inserted into database...+","+ph2+")"); out.println("Data is successfully inserted
when refreshing the page the data is stored in data base again
when refreshing the page the data is stored in data base again  Hi, In my application, I am adding form data in database on click of submit button.But the problem is, when user refreshes the page, the data added one more time
how to get data from database into dropdownlist in jsp
tutorial go through the link JSP Get Data Into Dropdown list From Database   ...how to get data from database into dropdownlist in jsp  Can anybody... the database and set it into dropdown list in jsp please help <br/>
Inserting data on a database in servlet - JSP-Servlet
Inserting data on a database in servlet  Hi I am following... to a databse by a servlet.I used the example in "Inserting Data In Database table... of a table,that is none of the data which i tried to enter into database by using
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
jsp programe for displaying data from database
jsp programe for displaying data from database  i am using JSP.i want to insert data into database and also want to display the things i have entered.../WebSevices/19592-retriving-data-from-sql-server-using-jsp-code-and-placing-them
PHP search data with different format
PHP search data with different format  How to search data with different format in PHP
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 <% Connection conn = null; ResultSet rs = null
what is the jsp coding to insert a data in database tables
what is the jsp coding to insert a data in database tables  Dear Sir, I Want to know the coding for insert the data from jsp to oracle database.. my...:8080/examples/jsp/1/insert.jsp"> <table> <tr><td>
JSP Get Data From Database
JSP Get Data From Database In this section we will discuss about how to get data from database using JSP. To get data from database to a JSP page we... example which lets you understand to fetch data from database in JSP
how to insert data in database using html+jsp
how to insert data in database using html+jsp  anyone know what... and database name. Here machine name id localhost and database name... = null; // declare a resultset that uses as a table for output data from
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  //Customer Name: <select name="name"> <% try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost
size of different basic data types
size of different basic data types   Write a simple program to find the size of different basic data types in java
how to get data from database into dropdownlist in jsp
how to get data from database into dropdownlist in jsp  Customer Name:<select name="name"> <% try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc
how to store the data in a array retrived from the database - JSP-Servlet
of an employee in a row which is entered at different times which is stored in database,and i need to disply all the employees record in a single jsp. pls can any...how to store the data in a array retrived from the database  hi
insert data into database
the data into the jsp page that data stored into the database.Here the error...insert data into database  hi,thanks for reply just i am doing student information project,frontend is jsp-servlet and backend is msaccess2007. i
where is my sqlite data files(.db) will be saved?
where is my sqlite data files(.db) will be saved?  Hi, i am using... with it well as embedded database. I want to know where my (sam.db) database file of SQLite will be stored in my computer? Also whether my .jar file will include the db
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE
DIFFERENT PAGES FOR DIFFERENT USERS ACCORDING TO THEIR ROLE  I HAVE A PROBLEM IN PHP CODING PLS HELP ME PROBLEM IS THAT I WANT DIFFERENT PAGES TO VIEW FOR DIFFERENT USERS WHEN THEY LOGIN ACCORDING TO THEIR ROLE IN DATABASE
Spring Security customized login from database
Spring Security customized login from database In this section, you will learn how to secure URL access using customized login where password stored in database table. EXAMPLE In the below example, we have created a customized login
How to Retrieve data from database in jsp
How to Retrieve data from database in jsp In this section we will discuss about how to fetch data from database table. We will give a simple example which will demonstrate you about fetching data from database table. Example We
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.  <html> <..."> <title>JSP Page</title> <style type
design chart takes data from database and through jsp page
design chart takes data from database and through jsp page  how can I design chart takes data from database and through in jsp page
 

 

 

DMCA.com