简体   繁体   English

web.xml错误页面不起作用,为什么?

[英]web.xml error-pages are not working, why?

I'm running out of ideas by now, and don't know what else to try. 到目前为止,我的想法已用尽,不知道还能尝试什么。 The point is not even one error-page is working, I just would like to know, what am I doing wrong?, here is the code: 关键是哪怕一个错误页面都无法正常工作,我只是想知道,我在做什么错?这是代码:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/sessionexpired.xhtml</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/500.xhtml</location>
</error-page>

When having this code in my web.xml I get this message: 当我的web.xml中包含此代码时,我收到以下消息:

XML read error: no element found XML读取错误:找不到元素

What this message means? 此消息是什么意思? how can I solve this? 我该如何解决? Thanks. 谢谢。

BTW, I have also tried to use filters to handle the ViewExpiredException , then it works the first time when I send the POST message and redirects to the sessionexpired.xhtml. 顺便说一句,我也曾尝试使用过滤器来处理ViewExpiredException ,然后它在我发送POST消息并重定向到sessionexpired.xhtml时第一次起作用。 But if I click backward and then make the POST call again BAM! 但是,如果我单击后退,然后再次进行POST呼叫BAM! I get again the ViewExpiredException . 我再次得到ViewExpiredException

UPDATE 30-NOV-2011 --[ALTERNATE SOLUTION]------------------------------------- 更新2011年11月30日-[替代解决方案] -------------------------------------

After a while I found that in order to make it work you have to specify the loation to .html or .jsp files , so it would end up being: 过了一会儿,我发现为了使其正常工作,您必须为.html或.jsp文件指定位置,因此最终结果是:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/sessionexpired.html</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/500.jsp</location>
</error-page>

Well, for those that are strugling with this issue using Glassfish 3.1, you can handle that problem by following this article to the letter, even thought I changed at the end to use sendRedirect() instead of the JSF navigator to render the sessionexpired.xhtml file, but that's your choice, it works fine. 好吧,对于那些使用Glassfish 3.1来解决此问题的人,您可以按照本文的开头来处理该问题,甚至认为我最后更改为使用sendRedirect()而不是JSF导航器来呈现sessionexpired.xhtml文件,但这是您的选择,效果很好。 Here you go: 干得好:

http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2 http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2

After you change the web.xml, have you do the ear or war redeployment? 更改web.xml之后,您是否进行了耳部或战争重新部署? Some of the application server might cache the old copy of web.xml if you directly go to server to modify the file. 如果您直接转到服务器来修改文件,则某些应用程序服务器可能会缓存web.xml的旧副本。 Hopefully it can work. 希望它可以工作。 :) :)

May be some problem try this may it helps.. 可能有问题,请尝试这样做可能会有所帮助。
<error-page> tag come after the <servlet-mapping> element. <error-page>标记位于<servlet-mapping>元素之后。

<web-app>
...
<servlet>
 ...
  </servlet>
  <servlet-mapping>
    .....
  </servlet-mapping>
  ...
  <welcome-file-list>
  ...
   </welcome-file-list>
  <error-page>
    <error-code>404</error-code>
    <location>/errorpages/html404.html</location>
  </error-page>
 <taglib>
 ...
 </taglib>
 ...
</web-app>

When having this code in my web.xml I get this message: 当我的web.xml中包含此代码时,我收到以下消息:

  XML read error: no element found 

As per the comments it turns out that you're seeing this in the browser instead of the expected error page. 根据评论,事实证明您是在浏览器中看到此错误,而不是预期的错误页面。 I initially interpreted it being mentiond by your IDE/editor due to a syntax error in web.xml . 我最初解释是由于web.xml的语法错误而被您的IDE /编辑器提及。 Your question wasn't entirely clear on that. 您的问题尚不完全清楚。

Well, the solution to that is easy: make sure that the <location> of the <error-page> matches the URL pattern of the FacesServlet . 好了,解决方法很简单:确保<error-page><location>FacesServlet的URL模式匹配。 Easiest would be to just map the FacesServlet on an URL pattern of *.xhtml . 最简单的方法是将FacesServlet映射到*.xhtml的URL模式。


BTW, I have also tried to use filters to handle the ViewExpiredException, then it works the first time when I send the POST message and redirects to the sessionexpired.xhtml. 顺便说一句,我也曾尝试使用过滤器来处理ViewExpiredException,然后它在我发送POST消息并重定向到sessionexpired.xhtml时第一次起作用。 But if I click backward and then make the POST call again BAM! 但是,如果我单击后退,然后再次进行POST呼叫BAM! I get again the ViewExpiredException. 我再次得到ViewExpiredException。

This is just caused by the page being requested from the browser cache instead of straight from the server. 这仅是由浏览器缓存而不是服务器直接请求页面引起的。 See also this answer for a concrete solution: browser back + viewscope beans . 另请参见此答案以获取具体解决方案: 浏览器返回+ Viewscope bean

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM