Tuesday, 6 September 2016

How to disable back button after Login in Java

Here is the simple programme when you login with your application it will disable the back button in browser

index.jsp

<%--
    Document   : index
    Created on : Sep 6, 2016, 1:17:40 PM
    Author     : ananddw
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login Page </title>
    </head>
    <body>
        <form action="sucess.jsp" method="post">
        <table>
            <tr>
                <td>UserName</td>
                <td><input type="text" name="uname" id="uname"/></td>
            </tr>
           
            <tr>
                <td>Password</td>
                <td><input type="password" name="pword" id="pword"/></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Login"/></td>
            </tr>
           
        </table>
            </form>
    </body>
</html>

sucess.jsp 

<%--
    Document   : sucess
    Created on : Sep 6, 2016, 1:24:13 PM
    Author     : ananddw
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <%
        String username = request.getParameter("uname");
        String password = request.getParameter("pword");
        System.out.println("User Name is " + username + "\t" + "and password is " + password);
    %>
    <body onload="preventBack()">
    <center>
        Hi <%=username%> welcome in Home Page You can't go back
    </center>
</body>
<script>
    history.pushState(null, null, document.title);
    window.addEventListener('popstate', function () {
        history.pushState(null, null, document.title);
    });

</script>
</html>


To Download Source Code or War Click here https://drive.google.com/drive/folders/0B5SLW_aQO5FiSFFnX1V4QzlzM00

No comments:

Post a Comment

Map class field to map

 import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class AutogeneratedClassMapper {     public static M...