title: how to store request object in session scope in jsp
body: <p>I was just doing random trick &amp; testing in my <code>jsp</code> pages. I wanted to store <code>request</code> scope object in <code>session</code> scope object using <code>Attributes</code>. After storing when tried to extract the value from request attribute (stored in session attribute), I got <code>null</code>. Why is it so?
  Following are my <code>jsp</code> files:</p>
  
  <p><strong>index.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;%request.setAttribute("request1", "requestValue"); %&gt;
  &lt;%session.setAttribute("req1", request); %&gt;
  &lt;br&gt;
  &lt;a href="jsp2.jsp"&gt;link&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>jsp2.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;br&gt;
  &lt;%HttpServletRequest rrrr=(HttpServletRequest)session.getAttribute("req1"); %&gt;&lt;br&gt;
  &lt;%=rrrr.getAttribute("request1")%&gt;&lt;br&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>browser output</strong></p>
  
  <pre><code>null
  </code></pre>
  
  <p><strong>expected output</strong></p>
  
  <pre><code>requestValue
  </code></pre>
  
  <p>.........................................................</p>
  
  <p>I need your guidance in this problem.</p>