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



Home Answers Viewqa Java-Beginners JSP Login Page Question

Have Programming Question? Ask it here!
 
 
 


Ankit Kumar
JSP Login Page Question
2 Answer(s)      2 years and a month 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
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  code for login page
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
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
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
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
login page with image
login page with image  I am writing program for login page.It consists of a image and the login details... how to write a java program using frames that have the default positions in any of the systems.. thanks   i had
Spring Login Page Error
Spring Login Page Error  Dear Sir/Madam, I used the spring login page code. The index page is working fine. When i try to entry login and password , i am getting the below error: Please help me out in this. Let me know if i
how to create a login page and registration page?
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
Login page validation on ipad
Login page validation on ipad  I am using userId & password labels and their corresponding textfield. Now I want to validate the details by single sign in button and want to switch on to next page. Used two labels again
JSP - Login
JSP - Login  how to disabled back button of the browser when user successfully logged
basic login and registration web page using jsp and servlet without using bean .....
basic login and registration web page using jsp and servlet without using bean .....  Hello Folks please i m totally beginner so guys please help me with very simple solution..... thnx
HTML login page code
HTML login page code  Hi all, I am writing my first HTML JavaScrip... the complete HTML JavaScript code for User Login Page. Thanks in Advance!   ...;td colspan=2><font size=3><center><b>HTML Login Page
login page validation
login page validation  hi could you please send me code for login validations Email validation and password email should be in correct format and valid password in java   import java.awt.*; import javax.swing.
login page php mysql example
login page php mysql example  How to create a login page for user in PHP Mysql? Please provide me a complete tutorial. Thanks in Advance
.Net and SQl 2000 Login page
.Net and SQl 2000 Login page  Please help me creating a login page using dot net using data base sql 2000
Jsp login with Cookie - JSP-Servlet
Jsp login with Cookie  9) Create an HTML page containing the following features a. Create a login JSP page with username , password and submit... cookies to store username and password. c. Open login JSP page on a new browser
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
jsp question
jsp question   sir plz tell me how can I create a page which is similar to feedback form in which if one option is empty then other option is inaccessible. for example it consists of name address etc. if name field is not filled
jsp/servlet login program
jsp/servlet login program  <%@ page language="Java" import...; </jsp:useBean> <jsp:forward page="hello"> <jsp:param name...;/TITLE></HEAD> <BODY> <jsp:useBean id="db" scope="request" class
login form - JSP-Servlet
login form  Q no.1:- Creat a login form in servlets?  Hi...*; import javax.servlet.http.*; public class Login extends HttpServlet...(); pw.println(""); pw.println("Login"); pw.println(""); pw.println
jsf login page - Java Server Faces Questions
jsf login page  how to create a login page and connect to database using abatis tool
Login & Registration - JSP-Servlet
Login & Registration  Pls tell how can create login and registration step by step in servlet. how can show user data in servlet and how can add...://www.roseindia.net/jsp/loginbean.shtml Hope that the above links will be helpful
program code for login page in struts by using eclipse
program code for login page in struts by using eclipse  I want program code for login page in struts by using eclipse
jsp question..
jsp question..  what should do in deployment descriptor after adding jstl jar files.. I am the the following message in console screen; The absolute cannot be resolved in either web.xml or the jar files deployed
Advertisements
 

 

 

DMCA.com