java - ICEFaces session 自动扩展

标签 java tomcat jsf icefaces java-ee-5

我有一个应用程序,其中用户经常让页面整天在浏览器中运行。该页面有一个 intervalrendered,每 30 秒更新一次数据。

但是,如果用户有一段时间没有与页面交互,它仍然会过期。只要浏览器打开并发出预定请求,我希望它自动扩展。

有没有一种方法可以在每次为其中一个页面触发预定渲染器时自动延长 session ?

最佳答案

当我的代码已经被 ICEFaces 每 30 秒调用一次时,我真的不想用 Javascript hack 来点击按钮。 ICEFaces 内部计时器的以下被黑变通办法似乎有效:

  private void updateSessionExpiration () {
      HttpSession sess = getSession();
      if (sess != null) {
        try {
            Field fld = SessionDispatcher.class.getDeclaredField("SessionMonitors");
            fld.setAccessible(true);
            Map map = (Map)fld.get(null);
            String sessID = sess.getId();
            if (map.containsKey(sessID)) {
                log.info("About to touch session...");
                SessionDispatcher.Monitor mon = 
                     (SessionDispatcher.Monitor)map.get(sessID);
                mon.touchSession();
            }
        } catch (Exception e) {
            log.error("Failed to touch session");
        }
      }
  }

此外,还有 ICEFaces 1.8.2RC1 (并且大概最终也会随着 ICEFaces 1.8.2 的发布版本一起发布),有两个新的解决方法可用:

HttpServletRequest request = (HttpServletRequest) servletRequest; 
HttpSession session = request.getSession(); 
if (session != null) { 
    SessionDispatcher.Monitor.lookupSessionMonitor(session).touchSession(); 
} 

或者,将它放在 web.xml 中以更新对特定模式中 URL 的任何命中:

<filter> 
    <filter-name>Touch Session</filter-name> 
    <filter-class>com.icesoft.faces.webapp.http.servlet.TouchSessionFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>Touch Session</filter-name> 
    <url-pattern>/seam/remoting/*</url-pattern> 
</filter-mapping> 

关于java - ICEFaces session 自动扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/738642/

相关文章:

java - 有没有办法使 PrintWriter 输出为 UNIX 格式?

java - QR 码显示为空白

web-services - 无法在 Tomcat Web 服务器(本地)上运行我的 Spring MVC 项目

jsf - 如何使用 modalDialog 警告用户 session 已过期?

java - 需要一个简单的 CMS。我应该定制现有的 CMS 还是从头开始构建?

ajax - f :ajax not working on tomcat7/eclipse

html - tomcat6 上的 webapp 中的 SVG 在 IE9 中不起作用

jsf - 在组件上切换验证器

java - JSF/Java 设计问题

java.lang.IllegalStateException : System services not available to Activities before onCreate() When trying to store users location as a variable 错误