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 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 Tutorials/Questions & Answers:
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
Advertisements
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
=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 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 and registration form using servlet and authentication through mysql
login and registration form using servlet and authentication through mysql  i made a simple login and rgistration form using servlet and authentication through mysql and whenevr i run it on tomcat a blank page is displayed plz
Login form and registration
Login form and registration  I need a complete code for ligin and new user registration form and validation
administrator login form
administrator login form   Hi iam using struts frame work backend as oracle .i want code for administrator login form thanks in advance
Spring login form application
Spring login form application  Hi Please give me the Spring login form application so that i can understand its flow ?   Hi please find the link of the tutorial Spring Applications
Login Form
Login Form       Login form in struts: Whenever you goes to access data from...; String query="select id from login where loginid='"+strUserName
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
java login form using netbeans
java login form using netbeans  how to connect an access database to a login form using netbeans
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
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 form validation - JSP-Servlet
login form validation  hi, how to validate the login form that contains user name and password using post method . the validation should not allow user to login in the address bar thanks regards, anand
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
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
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 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 form in jscript
Login form in jscript  For example the html script is <...; charset=utf-8" /> <title>:: validation form::</title> <script...;td align="center" valign="top"> <form name="form1" onsubmit
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
Login Form using Ajax
empty in the login page then a message is displayed as shown below:ADS_TO_REPLACE_5...Login Form using Ajax       This section provides you an easy and complete implementation of login form
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:ADS_TO_REPLACE_1 This example will display the login form to the user. If user
How to make login form in Struts 2?
How to make login form in Struts 2?  Hi, How to make login form in Struts 2? Thanks   Hi, If you want to learn to make Login form in Struts then check following tutorial: How to create Login Form in Struts2? 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 form using java bean in eclipse
login form using java bean in eclipse  I have made a college community website but i need to implement beans to my login and contact us page. how can i do
What is the use of Login Page?
; Login Form is the page where you can login to the application or the page... if they are getting the login form from a login page. (adsbygoogle... and password. So, login page will validate you to find if you are the authenticated
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
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
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
how to login form through spring dao module
how to login form through spring dao module  here i want to chek user details in database through form by using spring dao module.please give me some reference example to me
Database driven login form - Java Server Faces Questions
Database driven login form  Dear sir,madam, Greetings!! well, am a new user of java and i am programming using the netbeans IDE, what i need is code that; will create a database driven login form where users are authenticated
getting error in your login form code
getting error in your login form code  i tried your code for login form but i am getting an error.the error is undefined index userid...   hi friend, your form's input must have following : <input type
Spring 3 MVC Login Form Example
Spring 3 MVC Login Form Example  Spring 3 MVC Login Form Example index.jsp file have code.... Simple Form request will be handle...()); } My question is that, using above code how WEB-INF/views/simpleForm.jsp page
Spring 3 MVC Login Form Example
Spring 3 MVC Login Form Example  Spring 3 MVC Login Form Example index.jsp file have code.... Simple Form request will be handle...()); } My question is that, using above code how WEB-INF/views/simpleForm.jsp page
Login form using Jsp in hibernate - Hibernate
Login form using Jsp in hibernate   Hai Friend, As I new To hibernate, I'm facing problem in My project(JSP with hibernate).. My login form... and entering into Menu Form.. plz can any one help for my problem... Thanks
Login Form with Java GUI using Netbeans
Login Form with Java GUI using Netbeans  Hi there! I'm a beginner...(){ super("Login Authentication"); setSize(400,300); setLocation... have different user to login? Now that I've only administrator who is able
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
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
login authentication in jsp and servlet
login authentication in jsp and servlet  Hi, I am beginner in web... to make login authentication in jsp and servlet? Thanks   Hi, I to make login authentication in jsp and servlet you have to write code for database
PHP MySQL Login Form
Login Form using PHP and MySQL: In any website generally it is mandatory to have a login form to keep your data secure. In this regard we need to have... will study how to create a login form, connect with the database server and login
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
Login form in Struts2 version 2.3.16
How to create Login Form in Struts2? In this video tutorial I am explaining you about the source code of the program to create the Login form in Struts2.... This application presents a login form to the user and asks the user to enter "User
Login Form in SWT
Login Form in SWT       This section illustrates you how to create Login Form. To create a login... GridLayout(2, false)) sets the layout of the login form. The method setTextLimit(30
add cookies to login form in jsp by using struts2.0 framework
add cookies to login form in jsp by using struts2.0 framework  hi sir i implemented login.jsp page it include username and password field I used struts2.0 and hibernate3.0 and mysql database for login .jsp now i want to add
Login Screen of Application
form, action class, DAO code and necessary emailing code. Once the login is successful following form is displayed: ADS_TO_REPLACE_2 Now user can Update His... Login Screen of Application     
Struts 2 Login Form Example
Struts 2 Login Form Example tutorial - Learn how to develop Login form... you can create Login form in Struts 2 and validate the login action... the Struts 2 Login Form Example Step 1: Create a new dynamic project. Step 2: Add

Ads