Session Management using HttpSession Object in JSP Part – 2

Program 1

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>TODO write content</div>
    </body>
</html>

Program 2

<%-- 
    Document   : LoginPage
    Created on : Dec 7, 2023, 3:38:32 PM
    Author     : admin
--%>

<%@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>
    <body>
         <center>
             <form method="post" action="FirstPage.jsp"> 
           <table border="1">
               <tr>
                   <th>User Name</th>
                  <td><input type="text" name="txtuser"></td>
               </tr>
               <tr>
                   <th>Password</th>
                  <td><input type="password" name="txtpass"></td>
               </tr>
               <tr>
                   <td></td>
                  <td><input type="submit" value="submit"></td> 
               </tr>
           </table>    
         </center>    
    </body>
</html>

Program 3

<%-- 
    Document   : FirstPage
    Created on : Dec 7, 2023, 3:42:04 PM
    Author     : admin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page  session="true"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <A href="signout.jsp">signout</A>
         <center>
             <% 
                String user,pass;
                user=request.getParameter("txtuser");
                pass=request.getParameter("txtpass");
                out.println(user + "  "+pass);
                session.setAttribute("username", user);
                session.setAttribute("password", pass);
             %>
             <form method="post" action="SecondPage.jsp">
                 <input type="submit" value="Submit">
             </form>
         </center>    
    </body>
</html>

Program 4

<%-- 
    Document   : SecondPage
    Created on : Dec 7, 2023, 3:46:39 PM
    Author     : admin
--%>

<%@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>
    <body>
        <A href="signout.jsp">signout</A>
        <h1>Hello World! This is Second Page</h1>
        <% 
              String user,pass;
              user=session.getAttribute("username").toString();
              pass=session.getAttribute("password").toString();
              //out.println(session.isNew());
              out.println("User Name="+user);
              out.println("<br>Password="+pass);
              session.setAttribute("email", "[email protected]");
              session.setAttribute("org", "Data Flair Indore");
        %>
         <form method="post" action="ThirdPage.jsp">
                 <input type="submit" value="Submit">
             </form>
    </body>
</html>

Program 5

<%-- 
    Document   : ThirdPage
    Created on : Dec 7, 2023, 3:51:02 PM
    Author     : admin
--%>

<%@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>
    <body>
        <A href="signout.jsp">signout</A>
        <h1>Hello World! This is Third and Last Page</h1>
       <% 
       
             String user, pass,e,o;
             user = session.getAttribute("username").toString();
             pass = session.getAttribute("password").toString();
             e=session.getAttribute("email").toString();
             o=session.getAttribute("org").toString();
             //out.println(session.isNew());
             out.println("User Name=" + user);
             out.println("<br>Password=" + pass);
             out.println("<br>Email=" + e);
             out.println("<br>Org Name=" +o);
             
       %> 
    </body>
</html>

Program 6

<%-- 
    Document   : signout
    Created on : Dec 7, 2023, 3:54:15 PM
    Author     : admin
--%>

<%@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>
    <body>
             <% 
                session.invalidate();
                session=null;
                response.sendRedirect("LoginPage.jsp");
             %>
    </body>
</html>
courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *