Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Although not the best approach (I'd rather use EL <code>${_session}</code> than a <em>scriptlet</em>), this should work fine. Your problem lies somewhere else. Are you running the code you think you're running? How are you compiling and deploying the code? Didn't you trim too much off from the given example? The session is namely domain and context dependent, if you redirect to a different domain and/or context, then a new session would be created. Also, the session is backed by a cookie, does the browser have cookies enabled? Else you'll have to use <a href="http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletResponse.html#encodeRedirectURL%28java.lang.String%29" rel="nofollow noreferrer"><code>HttpServletResponse#encodeRedirectURL()</code></a> to append the session identifier to the redirect URL.</p> <pre><code>response.sendRedirect(response.encodeRedirectURL("page2.jsp")); </code></pre> <hr> <p><strong>Update</strong>: to debug if it's really the <em>same</em> session, do in the servlet:</p> <pre><code>System.out.println("Session ID: " + session.getId()); </code></pre> <p>and in the JSP:</p> <pre><code>&lt;p&gt;Session ID: ${pageContext.session.id}&lt;/p&gt; </code></pre> <p>Also installing a HTTP header tracker like <a href="http://getfirebug.com" rel="nofollow noreferrer">Firebug</a>'s <a href="http://getfirebug.com/network" rel="nofollow noreferrer"><em>Net</em></a> panel may bring new insights. The HTTP response should include a <code>Set-Cookie</code> header with the session ID and the subsequent HTTP requests should include a <code>Cookie</code> header with the same cookie name/value, usually <code>JSESSIONID</code> with a long hex value like as on <a href="http://tweakers.net/ext/f/FyyWop3fRWFENHLFqf969xTg/full.png" rel="nofollow noreferrer">this screenshot</a>.</p> <hr> <p><strong>Update 2:</strong> since I was suprised because a forward apparently fixes this issue, I tried to reproduce this on Tomcat 6 and Glassfish 3, but this approach works perfectly on the both servers. So I suspect a bug in the container used by Appengine, that it is not setting the cookie correctly during the redirect.</p> <p>As evidence, here's a screen which proves that Glassfish is setting the cookie by <code>Set-Cookie</code> <strong>and</strong> firing the redirect by <code>Location</code>:</p> <p><img src="https://tweakers.net/ext/f/9myLRcyizrx5QYAeVVhXgsIO/full.png" alt="alt text"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload