Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to collect them all in a <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Map.html" rel="nofollow noreferrer"><code>Map</code></a> using a <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionListener.html" rel="nofollow noreferrer"><code>HttpSessionListener</code></a> yourself.</p> <pre><code>public class HttpSessionCollector implements HttpSessionListener { private static final Map&lt;String, HttpSession&gt; sessions = new HashMap&lt;String, HttpSession&gt;(); @Override public void sessionCreated(HttpSessionEvent event) { HttpSession session = event.getSession(); sessions.put(session.getId(), session); } @Override public void sessionDestroyed(HttpSessionEvent event) { sessions.remove(event.getSession().getId()); } public static HttpSession find(String sessionId) { return sessions.get(sessionId); } } </code></pre> <p>Just register it in <code>web.xml</code> as follows to run it:</p> <pre><code>&lt;listener&gt; &lt;listener-class&gt;com.example.HttpSessionCollector&lt;/listener-class&gt; &lt;/listener&gt; </code></pre> <p>Then, anywhere you want just do <code>HttpSessionCollector.find(sessionId)</code> to get the <code>HttpSession</code> in question.</p> <hr> <p>That said, this is a <strong>huge</strong> smell. There are certainly better ways to solve the <em>actual</em> functional requirement than this ;) As I commented in your <a href="https://stackoverflow.com/questions/3092917/how-can-i-get-the-tomcat-jsessionid-on-the-client-side">follow-up question</a>:</p> <blockquote> <p>This is the 2nd time that you asked a question which in real world should never be practiced. Honestly said, this all smells. What is it, the problem for which you think that getting the <code>HttpSession</code> associated with JSESSONID in server side and getting the JSESSIONID value in client side is "the" solution? Elaborate about this in a new question, you'll get answers how to do it the right way. </p> </blockquote> <p>Take it serious. We're not teasing you, we're just trying to help you in the right direction to avoid that your project/webapp will break due to security holes and bad practices and/or that you will get fired.</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