关于session失效的问题

来源:百度知道 编辑:UC知道 时间:2024/05/02 10:48:33
给定某servlet程序的片段,如下:
public void doGet(HttpServletRequest request,HttpServletResponse response){
------------
}
要把session的失效时间设为30分钟,应该在下划线处插入()。(选择一项)
a)request.getSession().setTimeout(1800);
b)request.getSession().setTimeout(30);
c)request.getSession().setMaxInactiveInterval(1800);
d)request.getSession().setMaxInactiveInterval(30);
应该选什么?讲讲为什么?

HttpSession里面没有setTimeout方法的,所传的参数的单位的确为秒
应该选c,用setMaxInactiveInterval

以下是API文档里面setMaxInactiveInterval的解释:
setMaxInactiveInterval
void setMaxInactiveInterval(int interval)
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout.

Parameters:
interval - An integer specifying the number of seconds

b)request.getSession().setTimeout(30);

选 a

参数的单位是 秒

c
这种问题看API就知道了