Reset session in jsp without invalidating
<p>I want to reset the session in a JSP page without invalidating it.
The reason for this is, the user might have an already opened page using the session and invalidating it would throw a <code>NullPointerException</code>. Since a fresh session is already been catched, I don't want to add an additional catch-phrase. The goal is to clean all Attributes.</p>

<p>I am looking for something like:</p>



<pre class="lang-java prettyprint-override"><code>session = new HttpSession(); //this does obviously not work
</code></pre>

<p>an alternative would be (?)</p>

<pre class="lang-java prettyprint-override"><code>while(session.getAttributeNames().hasMoreElements()){
    session.removeAttribute(session.getAttributeNames().nextElement());
}    //cleans session?
</code></pre>

<p>But I am not sure, if this deletes some necessary session-attributes like login-data.</p>

<p>Is there a nice way to do this?</p>

<p><strong>Edit:</strong> The best solution would be, each time you open a certain page you create a new session for that window/tab until you close the tab or revisit that page in this tab. This question occurred by the attempt to solve <a href="https://stackoverflow.com/questions/35224995/how-to-have-several-sessions-for-same-user">this problem.</a></p>