Java examples on jsp.snippets
- How do I get web application context path in JSP?
- How do I include a page fragment into JSP?
- How do I write and read object from HTTP Session?
- How do I add comment in JSP pages?
- How to include page dynamically in JSP page?
- How do I forward request to another page in JSP?
- How to set and get properties of a bean in JSP?
- What are the scripting elements in JSP page?
- How to create JSP error page to handle exceptions?
- How do I use jsp:useBean action in JSP pages?
- How to disable scripting elements in JSP pages?
How do I write and read object from HTTP Session?
<%@ page import="java.util.Date" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Session Read & Write</title></head>
<body>
<%
//
// Creates a session attribute named login-date to store a java.util.Date.
//
session.setAttribute("login-date", new Date());
//
// Read back the java.util.Date object from the session attribute.
//
Date loginDate = (Date) session.getAttribute("login-date");
%>
Login Date: <%= loginDate %>
</body>
</html>