java中session-timeout怎么设置
在Java中,可以通过设置web.xml或者通过代码设置session的超时时间。
在web.xml中设置session超时时间:
在web.xml中找到<session-config>
标签,并在其中设置<session-timeout>
标签的值,以分钟为单位。例如,将session超时时间设置为30分钟:
<session-config>
<session-timeout>30</session-timeout>
</session-config>
通过代码设置session超时时间:
在Java代码中,可以通过使用setMaxInactiveInterval()
方法设置session的超时时间,以秒为单位。例如,将session超时时间设置为1800秒(30分钟):
HttpSession session = request.getSession();
session.setMaxInactiveInterval(1800);
需要注意的是,如果同时使用web.xml和代码设置session超时时间,以代码设置的为准。
阅读剩余
THE END