我有一个 ViewScoped JSF 页面。用户正在工作的地方存在一个 ace:dialog。如果用户在两个小时内没有点击,他的会话将被 tomcat 自动销毁。
如果用户在那两个小时后发送请求,我会重定向到登录页面(因为用户已注销)。问题是我变成了一个错误:
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
如果用户退出,有没有办法将每个请求重定向到登录页面?如果会话被破坏,我的 Backing Beans 会发生什么?
如果用户请求子站点但未登录,这就是我的重定向方式:
@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]);
}
谢谢!