JEE*_*oob 5 java session glassfish session-timeout java-ee
我是JEE的新手,这让我很困惑.根据HttpSession.html #setMaxInactiveInterval(int interval)文档
一个
interval的值zero以下表明会话应永不超时.
但是根据我的教科书(已经有几年了 - 所以我希望它不总是正确的)使用零作为参数会导致会话立即超时.
这段代码
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
session.setAttribute("foo", 42);
session.setMaxInactiveInterval(0);
out.println(session.getAttribute("foo"));//problem here
}
}
Run Code Online (Sandbox Code Playgroud)
在Glassfish 4.0上使用似乎从教科书而不是更新的官方文档确认理论,因为它返回HTTP状态500 - 内部服务器错误,错误消息
java.lang.IllegalStateException: getAttribute: Session already invalidated
这里发生了什么?这个Glassfish 4.0错误或文档是错误的吗?或者也许有第三种选择?
PS.这段代码的工作原理应该是负值(会话没有失效),我正在使用-1而不是0在我的代码中.我只是对有问题感兴趣0.
| 归档时间: |
|
| 查看次数: |
22030 次 |
| 最近记录: |