title: jsp session redirect
body: <p>i am facing trouble in applying session.</p>
  
  <p>index.jsp has simple login form which when submitted go to a servlet which create session and redirect to admin_home.jsp page, everything is fine here.</p>
  
  <p>But I want that when user directly want to go to admin_home.jsp, he will redirected to index.jsp page.Here is the problem:</p>
  
  <p>admin_home.jsp</p>
  
  <pre><code>&lt;body&gt;
  
  &lt;%
      session=request.getSession(false);
      if(session.getAttribute("User_ID")==null)
      {
          response.sendRedirect("index.jsp");
      }
  
  %&gt;
      &lt;jsp:include page="header.jsp"&gt;&lt;/jsp:include&gt;
  
      &lt;div&gt;
      &lt;div id="left"&gt;
               &lt;div id="photo"&gt;
                  &lt;img alt="" src="images/users_image/&lt;%out.println(session.getAttribute("User_ID").toString().concat(".jpg"));%&gt;" /&gt;
  
              &lt;/div&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>The login servlet is setting the value User_ID in session....</p>
  
  <p>So when user try to access admin_home.jsp directly he should redirect to index.jsp page...
  what is wrong in my code ....</p>