Reference Session Value Across JSP Page : Session « JSP « Java Tutorial






<html>
<head>
  <title>Session Example</title>
</head>

<body>

<% 
   String val = request.getParameter("name");
   if (val != null)
      session.setAttribute("name", val);
%>

<center>
<h1>Session Example</h1>

Where would you like to go?<br><br>

<a href="sessionExamplePage1.jsp">Page 1</a>
<a href="sessionExamplePage2.jsp">Page 2</a>

</body>
</html>
<html>
<head>
  <title>Session Example</title>
</head>

<body>

<center>
<h1>Session Example</h1>

Hello, <%= session.getAttribute("name") %>. Welcome to Page 1!

</body>
</html>
<html>
<head>
  <title>Session Example</title>
</head>

<body>

<center>
<h1>Session Example</h1>

Hello, <%= session.getAttribute("name") %>. Welcome to Page 2!

</body>
</html>
  Download:  JSPReferenceSessionValueAcrossJSPPage.zip( 4 k)








23.40.Session
23.40.1.Get Session ID, creation time and last accessed time
23.40.2.Set and get variable to a session
23.40.3.Session Scope Bean
23.40.4.Reference Session Value Across JSP Page