Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <%@page import="java.sql.Date"%>
  2. <%@page import="database.Database"%>
  3.  
  4.  
  5.  
  6. <%
  7. // Get session creation time.
  8. System.out.print("oi");
  9. Date createTime = new Date(session.getCreationTime());
  10.  
  11. // Get last access time of this Webpage.
  12. Date lastAccessTime = new Date(session.getLastAccessedTime());
  13.  
  14. String title = "Welcome Back to my website";
  15. Integer visitCount = new Integer(0);
  16. String visitCountKey = new String("visitCount");
  17. String userIDKey = new String("userID");
  18. String userID = new String("ABCD");
  19.  
  20. // Check if this is new comer on your Webpage.
  21. if (session.isNew() ){
  22. title = "Welcome to my website";
  23. session.setAttribute(userIDKey, userID);
  24. session.setAttribute(visitCountKey, visitCount);
  25. }
  26. visitCount = (Integer)session.getAttribute(visitCountKey);
  27. visitCount = visitCount + 1;
  28. userID = (String)session.getAttribute(userIDKey);
  29. session.setAttribute(visitCountKey, visitCount);
  30. %>
  31.  
  32. <html>
  33. <head>
  34. <title>Session Tracking</title>
  35. </head>
  36.  
  37. <body>
  38.  
  39. <center>
  40. <h1>Session Tracking</h1>
  41. </center>
  42.  
  43. <%
  44. database.Database db = new database.Database();
  45. db.testDB();
  46. %>
  47.  
  48. <table border = "1" align = "center">
  49. <tr bgcolor = "#949494">
  50. <th>Session info</th>
  51. <th>Value</th>
  52. </tr>
  53. <tr>
  54. <td>id</td>
  55. <td><% out.print( session.getId()); %></td>
  56. </tr>
  57. <tr>
  58. <td>Creation Time</td>
  59. <td><% out.print(createTime); %></td>
  60. </tr>
  61. <tr>
  62. <td>Time of Last Access</td>
  63. <td><% out.print(lastAccessTime); %></td>
  64. </tr>
  65. <tr>
  66. <td>User ID</td>
  67. <td><% out.print(userID); %></td>
  68. </tr>
  69. <tr>
  70. <td>Number of visits</td>
  71. <td><% out.print(visitCount); %></td>
  72. </tr>
  73. </table>
  74. </body>
  75. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement