0

I am using JBoss 7 and I have configure my session config in web.xml as follows:

<session-config>
<session-timeout>240</session-timeout>
<http-only>true</http-only>
</session-config>

However, in my servlet, i am getting a nullpointerexception when I try to retrieve the current session as follows:

request.getSession(false);

Am I missing anything?

user1066568
  • 717
  • 3
  • 15
  • 32

1 Answers1

0

That seems correct per the documentation.

Snippet:

Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.

If create is false and the request has no valid HttpSession, this method returns null.

After looking again at your web.xml snippet, it's not quite correct. The <http-only/> is not part of the <session-config/>. Move it into <cookie-config/> as per the following:

<session-config>
    <session-timeout>240</session-timeout>
    <cookie-config>
        <http-only>true</http-only>
    </cookie-config>
</session-config>
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
James R. Perkins
  • 16,800
  • 44
  • 60
  • Thanks James. I am able to retrieve a valid session if I do NOT have as true in my web.xml. Why is it that there's no session when is true? – user1066568 Nov 07 '12 at 01:55
  • I am setting the session attribute in a jsp file as follows "session.setAttribute("fileName", fileName)". I am also setting this attribute in the httpservletrequest object as "request.setAttribute("fileName", fileName)". However, in my java code, when I do "request.getSession(false)", I get a null session. And when I do "request.getAttribute("fileName"), I still get null. This is the behaviour I am seeing when I set to true in web.xml. Works fine when I remove the from my web.xml. Am I missing anything? Thanks for your help James – user1066568 Nov 07 '12 at 10:00