JSF Session timeout的页面跳转处理(亲测可以用)
来源:互联网 发布:51单片机最小系统焊接 编辑:程序博客网 时间:2024/05/01 08:32
JSF HTTP Session timeout,如果不加处理,会跳到错误页面
一般项目要求我们需要跳转到首页
java code:
package org.test.web;import javax.faces.FacesException;import javax.faces.application.Application;import javax.faces.application.ViewHandler;import javax.faces.component.UIComponent;import javax.faces.component.UIViewRoot;import javax.faces.context.ExternalContext;import javax.faces.context.FacesContext;import javax.faces.event.PhaseEvent;import javax.faces.event.PhaseId;import javax.servlet.http.HttpSession;public class PhaseListener implements javax.faces.event.PhaseListener { public static final String PHASE = "PHASE"; private static final String homepage = "index.jsp"; public void afterPhase(PhaseEvent event) { reportPhase(event, true); } public void beforePhase(PhaseEvent event) { // reportPhase(event, false); FacesContext context = event.getFacesContext(); ExternalContext ext = context.getExternalContext(); HttpSession session = (HttpSession) ext.getSession(false); boolean newSession = (session == null) || (session.isNew()); boolean postback = !ext.getRequestParameterMap().isEmpty(); boolean timedout = postback && newSession; if (timedout) { Application app = context.getApplication(); ViewHandler viewHandler = app.getViewHandler(); UIViewRoot view = viewHandler.createView(context, "/" + homepage); context.setViewRoot(view); context.renderResponse(); try { viewHandler.renderView(context, view); context.responseComplete(); } catch (Throwable t) { throw new FacesException("Session timed out", t); } } } public PhaseId getPhaseId() { return PhaseId.ANY_PHASE; } private static final String tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; private void DumpView (FacesContext ctx, UIComponent p, int lvl) { System.out.print (tabs.substring(0, lvl + 1)); System.out.println (p.getClass().getName()+": "+p.getClientId(ctx)+" "+p.getId()); for (UIComponent c : p.getChildren()) { DumpView(ctx, c, lvl + 1); } } private void DumpView (FacesContext ctx) { UIViewRoot r = ctx.getViewRoot(); System.out.println ("ROOT children "+r.getChildCount()); DumpView(ctx, r, 0); } private void reportPhase (PhaseEvent event, boolean after) { HttpSession session = (HttpSession) event.getFacesContext().getExternalContext().getSession(false); if (session != null) { if (after && event.getPhaseId() == PhaseId.RENDER_RESPONSE) { session.removeAttribute(PHASE); } else { if (!after) session.setAttribute(PHASE, event.getPhaseId()); } } if (!after && event.getPhaseId() == PhaseId.RENDER_RESPONSE) { //DumpView(event.getFacesContext()); } //System.out.println ("**********************"+(after ? "AFTER " : "BEFORE ")+event.getPhaseId()+" session="+session); System.out.flush(); }}
faces-config.xml
<lifecycle> <phase-listener>org.test.PhaseListener</phase-listener></lifecycle>
0 0
- JSF Session timeout的页面跳转处理(亲测可以用)
- JSF页面跳转时清除Session
- 可以跳转的页面
- Shiro中session超时页面跳转的处理
- 原来JSF页面可以这样将前台处理的数据传到后台处理!
- jsf中的页面跳转
- python session过期timeout处理
- session.timeout的设置
- frameset、iframe框架登录跳转, 处理session为空的登录页面问题
- ajax提交session超时跳转页面使用全局的方法来处理
- ajax session失效后,跳转到登录页面的全局处理
- spring security 处理session 超时跳转到登录页面
- ajaxsetup,结合拦截器处理session过期,跳转登录页面
- session 超时 页面跳转
- session 超时 页面跳转
- session超时,跳转页面
- JSF session的用法
- JSF session的用法
- Cocos2d-x 3.x新事件分发机制总结
- 正则表达式基本语法
- Android Gson
- JMeter入门(2):一个简单实例
- IOS学习笔记31—两个ViewController间传值(二)
- JSF Session timeout的页面跳转处理(亲测可以用)
- Android中对付ANR的N种武器
- 姑娘,你不是一朵花
- spring DelegatingFilterProxy管理过滤器
- 组播MAC地址
- 20150114,微软1月14日发布8个安全补丁
- MYSQL之“EXPLAIN语句简介”
- Android API 指南 - 【服务 Service】
- 2013年7月和2013年8月编程语言排行榜