为什么FullAjaxExceptionHandler不是简单地执行的ExternalContext#重定向()? [英] Why FullAjaxExceptionHandler does not simply perform an ExternalContext#redirect()?

查看:146
本文介绍了为什么FullAjaxExceptionHandler不是简单地执行的ExternalContext#重定向()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OmniFaces,在 FullAjaxExceptionHandler ,在已经找到了正确的错误页面使用,调用JSF运行时构建视图和渲染,包括AJAX调用的页面它代替。

In OmniFaces, the FullAjaxExceptionHandler, after having found the right error page to use, calls the JSF runtime to build the view and render it instead of the page that includes the AJAX call.

为什么呢?恕我直言,这将是简单的,只是执​​行的ExternalContext#重定向()?有没有具体的理由这样做呢?

Why this? IMHO it would be simpler to just perform a ExternalContext#redirect()? Are there specific reasons to do this?

<子>的我们正在编写我们自己的ExceptionHandler基于FullAjaxExceptionHandler,想了解这种设计背后的原因。

推荐答案

FullAjaxExceptionHandler 更是让在Ajax请求的异常表现的正是主要目标一样在非Ajax请求例外。开发人员必须能够重用在这两个条件下的错误页面,而无需担心的情况,而执行错误页面。

The primary goal of the FullAjaxExceptionHandler is to let exceptions during ajax requests to behave exactly the same as exceptions during non-ajax requests. The developer must be able to reuse the error pages across both conditions without worrying about the condition while implementing the error pages.

一个重定向是不是在非Ajax请求的正常流程的一部分。默认&LT;错误页&GT; 的web.xml 执行着显示错误页面,而不是机制重定向。如果进行重定向,所有的错误页面请求的属性,如中的javax.servlet.error.exception 可能会迷路,并呈现为。此外,通常的做法是将错误页面中 / WEB-INF 来prevent从终端用户能够直接访问(和书签和共享)他们。一个重定向要求他们公开访问,这表明一个主要的设计问题(是intented目标页面实际上是一个真正的错误页面?)。

A redirect isn't part of the normal flow during non-ajax requests. The default <error-page> mechanism in web.xml performs a forward to display the error page, not a redirect. If a redirect was performed, all error page request attributes such as javax.servlet.error.exception would get lost and render as null. Moreover, normal practice is to place error pages in /WEB-INF to prevent endusers from being able to directly access (and bookmark and share) them. A redirect would require them to be publicly accessible, which indicates a major design problem (is the intented target page actually a real error page?).

如果你真的需要从你的错误页面执行重定向到/,要么homegrow自定义异常处理程序,其中明确调用的ExternalContext#重定向()和不使用的web.xml &LT;错误页&GT; 机制,或添加&LT; META HTTP -equiv =刷新......&GT; 到有问题的错误页面的HTML头(例如这里)。

If you really need to perform a redirect to/from your error page, either homegrow a custom exception handler which explicitly invokes ExternalContext#redirect() and doesn't utilize web.xml <error-page> mechanism, or add a <meta http-equiv="refresh" ...> to the HTML head of the error page in question (example here).

在情况下,你真的打算重定向到一些登录页面时, ViewExpiredException 时,那么你应该认识到,还有的不记录用户的情况之间有很大的不同在和会话/视图已过期。对于前者,你不应该追赶 ViewExpiredException 可言,但用一个简单的 Servlet过滤器它检查,如果用户登录和重定向因此, FacesServlet的调用很久以前。一个正常的认证框架(JAAS,四郎,春季安全等),也适用这种方式。

In case you actually intended to redirect to some login page when a ViewExpiredException occurs, then you should realize that there's a big difference between the cases of "User is not logged in" and "Session/view is expired". For the former, you should not be catching ViewExpiredException at all, but use a simple servlet filter which checks if the user is logged in and redirect accordingly, long before the FacesServlet is invoked. A normal authentication framework (JAAS, Shiro, Spring Security, etc) also works that way.

  • <一个href="http://stackoverflow.com/questions/12257928/what-is-the-good-approach-to-forward-the-exception-from-servlets-to-a-jsp-page">What是很好的方法,以异常的servlet的转发到一个JSP页面?
  • <一个href="http://stackoverflow.com/questions/11277366/what-is-the-difference-between-redirect-and-navigation-forward-and-when-to-use-w">What是重定向和导航/着,什么时候使用什么区别呢?
  • <一个href="http://stackoverflow.com/questions/10534187/why-use-a-jsf-exceptionhandlerfactory-instead-of-error-page-redirection/">Why使用JSF ExceptionHandlerFactory而不是&LT;错误页&GT;重定向?
  • 检查是否存在会话JSF
  • <一个href="http://stackoverflow.com/questions/14580267/authorization-redirect-on-session-expiration-does-not-work-on-submitting-a-jsf-f/">Authorization重定向会话过期不上提交JSF表单的工作,页面保持不变
  • What is the good approach to forward the exception from servlets to a jsp page?
  • What is the difference between redirect and navigation/forward and when to use what?
  • Why use a JSF ExceptionHandlerFactory instead of <error-page> redirection?
  • Check if session exists JSF
  • Authorization redirect on session expiration does not work on submitting a JSF form, page stays the same

这篇关于为什么FullAjaxExceptionHandler不是简单地执行的ExternalContext#重定向()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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