কম্পিউটার টিউটোরিয়াল

JSP-এ সেশন মেইনটেনেন্সের ওয়ার্কিং উদাহরণ


এই উদাহরণ বর্ণনা করে কীভাবে HttpSession অবজেক্ট ব্যবহার করে একটি সেশনের ক্রিয়েশন টাইম এবং লাস্ট-অ্যাক্সেসড টাইম জানা যায়। যদি ইতিমধ্যে কোনো সেশন না থাকে, তবে রিকোয়েস্টের সাথে একটি নতুন সেশন অ্যাসোসিয়েট করা হবে।

<%@ page import = "java.io.*,java.util.*" %> <%    // Get session creation time.    Date createTime = new Date(session.getCreationTime());    // Get last access time of this Webpage.    Date lastAccessTime = new Date(session.getLastAccessedTime());    String title = "Welcome Back to my website";    Integer visitCount = new Integer(0);    String visitCountKey = new String("visitCount");    String userIDKey = new String("userID");    String userID = new String("ABCD");    // Check if this is new comer on your Webpage.    if (session.isNew() ) {       title = "Welcome to my website";       session.setAttribute(userIDKey, userID);       session.setAttribute(visitCountKey, visitCount);    }    visitCount = (Integer)session.getAttribute(visitCountKey);    visitCount = visitCount + 1;    userID = (String)session.getAttribute(userIDKey);    session.setAttribute(visitCountKey, visitCount); %> <html>    <head>       <title>Session Tracking</title>    </head>    <body>    <center>       <h1>Session Tracking</h1>     </center>     <table border = "1" align = "center">       <tr bgcolor = "#949494">           <th>Session info</th>          <th>Value</th>       </tr>       <tr>           <td>id</td>          <td><% out.print( session.getId()); %></td>       </tr>       <tr>          <td>Creation Time</td>          <td><% out.print(createTime); %></td>       </tr>       <tr>          <td>Time of Last Access</td>          <td><% out.print(lastAccessTime); %></td>       </tr>       <tr>           <td>User ID</td>           <td><% out.print(userID); %></td>       </tr>       <tr>          <td>Number of visits</td>          <td><% out.print(visitCount); %></td>       </tr>       </table>    </body> </html>

উপরের কোড main.jsp-এ রেখে https://localhost:8080/main.jsp অ্যাক্সেস করলে নিচের রেজাল্ট দেখাবে:

Welcome to my website

Session Information

Session infovalue
id0AE3EC93FF44E3C525B4351B77ABB2D5
Creation TimeTue Jun 08 17:26:40 GMT+04:00 2010
Time of Last AccessTue Jun 08 17:26:40 GMT+04:00 2010
User IDABCD
Number of visits0

  1. QR কোড তৈরি করে ওয়ায়ফাই সিগন্যাল সহজে শেয়ার করার পদ্ধতি (উদাহরণ)

  2. Windows 10 Photos App-এ Export/Share ফাংশন কাজ না করলে সমাধান

  3. ডিস্কর্ড স্ক্রিন শেয়ারিংয়ে অডিও সমস্যা সমাধান করার পদ্ধতি

  4. উইন্ডোজ ১০-এ ডিস্কর্ড স্ক্রিন শেয়ারিং সমস্যা সমাধান - দ্রুত ফিক্স গাইড