Java会话-无法转换为void
我正在尝试延长/控制应用程序中的会话寿命 现在是这样Java会话-无法转换为void,java,session,Java,Session,我正在尝试延长/控制应用程序中的会话寿命 现在是这样 request.getSession(true); 我看到的例子表明你可以使用这种方法 request.getSession(true).setMaxInactiveInterval(15*60); //in seconds; 但是我得到了以下错误 cannot convert from void to HttpSession 第一个是HttpServletRequest上的方法,并返回HttpSession 公共HttpSession
request.getSession(true);
我看到的例子表明你可以使用这种方法
request.getSession(true).setMaxInactiveInterval(15*60); //in seconds;
但是我得到了以下错误
cannot convert from void to HttpSession
第一个是
HttpServletRequest
上的方法,并返回HttpSession
公共HttpSession getSession(布尔创建)
第二个是对HttpSession
本身的方法调用,不返回任何内容。这是一个二传手
public void setMaxInactiveInterval(int interval)
如果需要HttpSession
变量(供以后进一步使用),则必须将getSession
结果分配给该变量,然后调用setMaxInactiveInterval
setMaxInactiveInterval()不返回值。请发布您的真实代码。您是否试图将setMaxInactiveInterval(15*60)的结果分配给HttpSession变量?显然,您正在尝试HttpSession session=request.getSession(true).setMaxInactiveInterval(15*60)代码>这是错误的。我现在明白了--HttpSession session=request.getSession(true);session.setMaxInactiveInterval(15*60);//10分钟