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?

4

1 回答 1

0

根据文档,这似乎是正确的。

片段:

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.

再次查看您的web.xml代码段后,它并不完全正确。<http-only/>不是 的一部分<session-config/><cookie-config/>按照以下方式将其移入:

<session-config>
    <session-timeout>240</session-timeout>
    <cookie-config>
        <http-only>true</http-only>
    </cookie-config>
</session-config>
于 2012-11-06T21:57:13.390 回答