会话无效后,FullAjaxExceptionHandler不会重定向到错误页面 [英] FullAjaxExceptionHandler does not redirect to error page after invalidated session

查看:144
本文介绍了会话无效后,FullAjaxExceptionHandler不会重定向到错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Omnifaces FullAjaxExceptionHandler( http://showcase.omnifaces.org/exceptionhandlers/FullAjaxExceptionHandler ).会话无效后,它不会重定向到指定的错误页面.

I am having issues with the Omnifaces FullAjaxExceptionHandler (http://showcase.omnifaces.org/exceptionhandlers/FullAjaxExceptionHandler). It does not redirect to the specified error page after the session is invalidated.

我的faces-config中包含以下内容:

I have the following in my faces-config:

<factory>
    <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>

以及我的web.xml中的以下内容:

And the following in my web.xml:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/pages/error/viewExpired.html</location>
</error-page>

在使会话无效之后,从用户的角度看,似乎什么都没有发生.该应用程序只是死".在我的控制台中,我看到以下Ajax请求:

After I invalidate the session, from a user's perspective nothing seems to happen. The application is just 'dead'. In my console I see the following Ajax request:

  • POST到原始facelet页面,响应码为302
  • 使用代码200进入登录页面(但是什么也没有发生,因为它是通过Ajax请求的)

我正在运行MyFaces 2.1.10,Primefaces 3.5,Primefaces扩展0.6.3& WebLogic 12c上的Omnifaces 1.4.1

I am running MyFaces 2.1.10, Primefaces 3.5, Primefaces Extension 0.6.3 & Omnifaces 1.4.1 on WebLogic 12c

有人可以在正确的方向帮助我吗?如何使FullAjaxExeptionHandler正常工作?

Could anyone help me in the right direction? How do I get the FullAjaxExeptionHandler to work properly?

谢谢

推荐答案

原始facelet页面的POST,响应代码为302

这是不对的.对JSF ajax请求的重定向必须具有200的响应代码,并带有特殊的XML响应,该响应带有<redirect>元素,其url属性中具有目标URL.

This is not right. A redirect on a JSF ajax request must have a response code of 200 with a special XML response with a <redirect> element with target URL in its url attribute.

因此,这表明您在JSF有机会处理ViewExpiredException的很早之前就在某个地方手动使用了HttpServletResponse#sendRedirect().

This thus indicates that you manually used HttpServletResponse#sendRedirect() somewhere long before JSF has the chance to deal with ViewExpiredException.

也许您在某个Servlet过滤器的某处,该过滤器检查某些会话属性并根据其存在/状态发送重定向?然后应根据以下答案操作该过滤器: JSF过滤器为了识别JSF ajax请求并返回一个特殊的XML响应而不是302响应,请在初始重定向后不重定向" .

Perhaps you've somewhere a servlet filter which checks some session attribute and sends a redirect based on its presence/state? That filter should then be manipulated based on the following answer: JSF Filter not redirecting After Initial Redirect in order to recognize JSF ajax requests and return a special XML response instead of a 302 response.

例如

if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
    response.setContentType("text/xml");
    response.getWriter()
        .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
        .printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", loginURL);
} else {
    response.sendRedirect(loginURL);
}

这与FullAjaxExceptionHandler完全无关. JSF没有机会抛出ViewExpiredException,因为您已经预先发送了自己的重定向.

This all is completely unrelated to the FullAjaxExceptionHandler. JSF didn't have any chance to throw a ViewExpiredException because you're already sending a redirect yourself beforehand.

这篇关于会话无效后,FullAjaxExceptionHandler不会重定向到错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆