注销时Java JSF重定向
我有一个可视范围的JSF页面。存在用户正在使用的ace:对话框。如果用户在两小时内没有点击,他的会话将自动被tomcat破坏 如果用户在两小时后发送请求,我将重定向到登录页面(因为用户已注销)。问题是我变成了一个错误:注销时Java JSF重定向,java,jsf-2,Java,Jsf 2,我有一个可视范围的JSF页面。存在用户正在使用的ace:对话框。如果用户在两小时内没有点击,他的会话将自动被tomcat破坏 如果用户在两小时后发送请求,我将重定向到登录页面(因为用户已注销)。问题是我变成了一个错误: java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed 如果用户注销,是否有办法将每个请求重定向到登录页面? 如果会话被破坏,我的备份be
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
如果用户注销,是否有办法将每个请求重定向到登录页面?
如果会话被破坏,我的备份bean会怎么样
如果用户请求子网站且未登录,则这是我的重定向方式:
@PostConstruct
public void initialize() {
logger.debug("Start - " + new Throwable().getStackTrace()[0]);
if (hasReadAccess()) {
FacesContext.getCurrentInstance().getExternalContext().redirect(pPath);
return;
}
logger.debug("End- " + new Throwable().getStackTrace()[0]);
}
这就是我的代码,如果用户发送ajax请求,例如使用rowEditListener:
public void rowEditListener(RowEditEvent ev) {
logger.debug("Start - " + new Throwable().getStackTrace()[0]);
if (hasReadAccess()) {
FacesContext.getCurrentInstance().getExternalContext().redirect(pPath);
return;
}
// do something
logger.debug("End - " + new Throwable().getStackTrace()[0]);
}
谢谢 看:只是一个旁注。仅为获取当前方法的名称而创建异常代价太高,最好使用
Thread.currentThread().getStackTrace()[1].getMethodName()
感谢您提供的异常提示和链接。我检查它。
you can use spring:
public void logout() {
try {
SecurityContextHolder.getContext().setAuthentication(null);
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
FacesContext.getCurrentInstance().getExternalContext()
.redirect(FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath() + "/j_spring_security_logout?faces-redirect=true");
} catch (Exception e) {
}
}