Home Answers Viewqa JSP-Servlet redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.

 
 


Nishit Ranjan
redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.
3 Answer(s)      a year ago
Posted in : JSP-Servlet

I am successfully able to create a session on successful login, but I want to display the welcome page on the parent page itself instead of getting redirected to welcome.jsp,whisch is a different page altogether.

Please Help Urgently.

View Answers

June 1, 2012 at 5:14 PM


The given code accepts username and password from the user and check whether the user is valid. If user is valid, welcome message will get displayed. Otherwise, the login will get redirected again.

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="http://localhost:8080/examples/Login" 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="Submit"></td></tr>
</table>
</form>
</html>

2)Login.java:

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Login extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { 

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try{
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        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("/examples/jsp/login.jsp");
          }
    }
    catch (Exception e) {
    e.printStackTrace();
    }
}
}

June 1, 2012 at 5:16 PM


The given code accepts username and password from the user and check whether the user is valid. If user is valid, welcome message will get displayed. Otherwise, the login page will get redirected again with error message.

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="Submit"></td></tr>
</table>
</form>
</html>
<%String msg=request.getParameter("msg");
if(msg!=null){
    %>
<label><font color="red"><%=msg%></font></label> 
<%
}
    %>

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?msg=Invalid Username or Password");
          }
%>

June 1, 2012 at 5:17 PM










Related Pages:
redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.
redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.  I am...=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'"); int
Login Form
of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so...Login Form  I have 8 jsp pages.Each of them has three columns:Left
Login Form
of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so...Login Form  I have 8 jsp pages.Each of them has three columns:Left
login form
(); ResultSet rs=st.executeQuery("select * from login where username='"+value1...login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components
login form
=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where...login form  sir my next form consists logout button when i click on it it showing login form but next form window is not closing but the components
login
login  how to create login page in jsp   Here is a jsp code that creates the login page and check whether the user is valid or not. 1)login.jsp: <html> <form name="form" method="post" action="check.jsp">
login
(); ResultSet rs=st.executeQuery("select * from login where username='"+value1... JTextField text1,text2; Login() { final JFrame f=new JFrame("Login Form... loggedinto next page   Hi Friend, Try the following code: 1
Login authentication & mysql - Java Beginners
* FROM login where username='"+value1+"' && password='"+value2...Login authentication & mysql  Hi , Could you guide or provide sample coding for the following scenerio. I need to code authentication for user
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login Form
Login Form       Login form in struts: Whenever you goes to access data from... query for checking password  String query="select id from login where
Login Form using Ajax
in the login page then a message is displayed as shown below: If you...;Password" field empty in the login page then a message is displayed as shown below...Login Form using Ajax      
PHP User Authentication Login and password check Tutorial
the number of times a url has been clicked is stored, URL is where the page... * FROM $table WHERE id='$id'"; $result = mysql_query($query); $tab... has been trigger, to add 1 to the given row. Sound easy enough? The fields
Login Form in Java - Java Beginners
= st.executeQuery("SELECT * FROM login where username='"+value1+"' && password='"+value2...Login Form in Java  Hi, In my Project, I am using Java-JDBC-Mysql... Authenticated person can access these module. I create table in my-sql where fields
login authentication - Java Beginners
login authentication  i 've problem in authenticating users thru jsp... giving user name and pwd in the jsp page, though it is wrong the jsp page shows... = con.createStatement(); // get data from register table
Login Screen of Application
/he has to again go through the registration process by selecting a new Login Id... form is displayed: Now user can Update His/Her profile... Login Screen of Application     
JSP Login Page Question
JSP Login Page Question  hey..i have a login page where different... and displayed it on the welcome page. Apart from this if user is not registered... can see only his data after login where different users data are stored
Login form
of login form will really help to understand jsp page. In this  example we... Login Form with jsp      ... are going to insert the data in the login form which will be displayed onto
How to put the image in footer in login form ?
(); ResultSet rs=st.executeQuery("select * from login where username...How to put the image in footer in login form ?  Hi, how to put the image in footer in login form ?   Here is an example that shows image
Display Logo on login form using swing
to display a logo in login form using swing components. Here is an example where... displayed on the login form. Example: import javax.swing.*; import java.sql....("select * from login where username='"+value1+"' and password='"+value2
PHP SQL Login
; This Application illustrates how to create a login page where only... a userlogin.php page which has a form with two input fields and one submit... works as the action page where we check both field from database table whether
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 in jsp
(); ResultSet rs=st.executeQuery("select * from login where username='"+user... 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
JDbc Login Authentication
JDbc Login Authentication  Pease Please.. Send Me one Login Authentication Using ComboBox.From Servlet and jsp with sessions I am new to sessions Please Help Me... Index.jsp <form action="Clas.java" Method="post">
JSP:HTML Form in-place Editing - JSP-Servlet
to achieve is - user fills out a form on one page. On the SAME page...JSP:HTML Form in-place Editing  Hi, I want to thank the people... developer's needs. This is a follow up to the HTML Form in-place editing. The code
Example of login form validation in struts2.2.1framework.
Example of login form validation in struts2.2.1 framework. In this example, we will introduce you to about the login form validation in struts2.2.1 framework. Our login form validation example does not validate the user against
login example
login example  1.Loginpage.jsp <%@ page language="java...(); String searchQuery = "select * from users where...-Type" content="text/html; charset=windows-1256"> <title>Login
login example
login example  1.Loginpage.jsp <%@ page language="java...(); String searchQuery = "select * from users where...-Type" content="text/html; charset=windows-1256"> <title>Login
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
How to put the logo in login form using swings/awt?
=con.createStatement(); ResultSet rs=st.executeQuery("select * from login where... How to put the logo in login form using swings/awt?  Hi, How to put the logo in login form using swings/awt? I write the login form is working
Spring alternative to Form Based Login
. Using a login form we can use the jspringsecurity_check. How can we do it by sending a web service call and not using any form based authentication...Spring alternative to Form Based Login  print("code sample");how can
standart login form for messenger in java
standart login form for messenger in java  hi i need login from for chating messenger in java. but its structure would like this Home Register Login User ID Password   Hi Friend
standart login form for messenger in java
standart login form for messenger in java  hi i need login from for chating messenger in java. but its structure would like this Home Register Login User ID Password   Hi Friend
PHP SQL Login
PHP SQL Login  This Application illustrates how to create a login page where authorized user can login and further process. In this application we create a userlogin.php page where we create a form with two input fields and one
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
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution
Jdbc Login Page Validation using Combobox
Jdbc Login Page Validation using Combobox  I got Login By this code i want to login by validating with combobox....The link which you send its...(); String query = "select uname,password from dblogin where uname='"+name
lOGIN according to der roles
(); ResultSet rs=st.executeQuery("select * from login where username='"+user...lOGIN according to der roles  how to login a user according to roles and page will should be same content will be different   1)index.jsp
Authentication
Authentication  The developer has to create a JavaBean... interface for login */ } public void addLoginListener(LoginListener login) { this.login = login; } public void fireLoginEvent(LoginEvent loginE
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... of that particular user will get retrieved from the database and displayed it on the welcome
login
login  i want to now how i can write code for form login incolude user and password in Jcreator 4.50   Hello Friend, Visit Here Thanks
verfication of user login and then redirecting it to user defined page
verfication of user login and then redirecting it to user defined page  hi, i have a login page that..calls the servlet..and i have used redirect...,the html page calls teh servlet..but..the servlet.is not redirecting to a user defined
Struts 2.1.8 Login Form
Struts 2.1.8 Login Form      ... to validate the login form using Struts 2 validator framework. About the example: This example will display the login form to the user. If user enters Login Name
Login Authentication using Bean and Servlet In JSP
;/body> <html> Output: Login Authentication form : After... Login Authentication using Bean and Servlet In JSP... developed a web application of login authentication using Bean  in JSP. Five
SWT login form - Swing AWT
SWT login form  Hi, I want code to create a login form in SWT. My requirement is that when the user clicks "enter" button from keyboard "login...(2, false)); shell.setText("Login form"); label1=new Label(shell
html login page with ajax
html login page with ajax  hi all... i want to create a login page... and password from the user and check whether the user is valid or not by using ajax...); xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded
For my website,As soon as the user is able to succesfully login, a Testimonial form appears.
For my website,As soon as the user is able to succesfully login, a Testimonial form appears.  For my website,As soon as the user is able to succesfully login, a Testimonial FORM appears in the same page. How to do. Please Help
login authentication - Java Beginners
login authentication  i 've designed the jsp page for login. now i need to connect it with the bean and do authentication for the login for the "register" table in mysql. can anybody help me with the code immediately
Struts Login Authentication
Struts Login Authentication  Hi Sir, Am doing a project in a struts 1.2,i want login authentication code fro that, only authenticated user can login into application,i am using back end as Mysql.so send me code as soon
login
want the code for login.. i created design it contains the field of user name and password and the submit button.. when i click the submit button it has to check the user name and password from the data base.. please help me for the code