JSF 1.2异常处理 [英] JSF 1.2 Exception Handling

查看:302
本文介绍了JSF 1.2异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我们应用程序中的异常处理。我使用try catch块来捕获我的代码中发生的异常,我也可以通过编写监听器并在faces-config.xml中注册监听器来处理超时异常。



但是,在构造函数或错误代码500,400等中,我遇到了诸如NullPointerException等意外错误的问题。



我使用web.xml中的标签

 < error-page> 
< exception-type> java.lang.Exception< / exception-type>
< location> /sc00/ErrorPage.jsp< / location>
< / error-page>

我尝试了很多方法来处理异常,任何人都可以帮助我找出解决方案。我尝试处理这些异常时出现的错误如下:



我正在使用JSF 1.2,服务器是websphere 8



控制台显示以下异常。

  com.ibm.ws.webcontainer.servlet.ServletWrapper服务SRVE0014E:未捕获的服务()异常根本原因Faces Servlet:javax.servlet.ServletException 

E com.ibm.ws.webcontainer.servlet.ServletWrapper服务SRVE0068E:其中一个服务方法抛出异常的[MembershipEligibilityScreensEAR]中的servlet [/sc00/ErrorPage.jsp]。异常创建:[java.lang.RuntimeException:FacesContext not found

我的错误页面在/ WebContent / sc00 / ErrorPage.jsp,ErrorPage.jsp没有与之关联的后备bean。



许多解决方案要求我查看Faces Servlet的URL路径,在我的web.xml中,servlet映射如下:

 < servlet> 
< servlet-name> Faces Servlet< / servlet-name>
< servlet-class> javax.faces.webapp.FacesServlet< / servlet-class>
< load-on-startup> 1< / load-on-startup>
< / servlet>

< servlet-mapping>
< servlet-name> Faces Servlet< / servlet-name>
< url-pattern> *。faces< / url-pattern>
< / servlet-mapping>
< servlet-mapping>
< servlet-name> Faces Servlet< / servlet-name>
< url-pattern> / faces / *< / url-pattern>
< / servlet-mapping>

我的faces-config.xml中的所有路径都是/ FolderName / JspName,它们工作正常他们甚至在Navigation.xml中都可以正常工作。



我如何将其导航到ErrorPage.jsp,有没有什么办法让我可以为这种问题写一个监听器



对于发布太多冗余问题抱歉,我是JSF的新手,我不知道StackOverflow的规则,对于我造成的问题,我深表歉意。

解决方案

  java.lang.RuntimeException:找不到FacesContext 

当您要求包含JSF组件的JSP页面,该URL不匹配 FacesServlet 的URL模式(谁负责创建 FacesContext )。



您需要更改错误页面位置以匹配 facesServlet 定义在 web.xml 中。根据您关于此主题的重复问题,这其中包括 *。 ,因此如下设置错误页面位置应该与我在建议的第一个问题

  ;地点> /sc00/ErrorPage.faces< /地点> 


I am working on exception handling in our Application. I used try catch blocks to catch the exceptions occured in my code and i also could handle the time out exceptions by writing a listener and registering the listener in "faces-config.xml".

But i am facing problems in catching unexpected errors like "NullPointerException" in constructor or error Codes 500, 400 etc.

i used the tags in the "web.xml"

<error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/sc00/ErrorPage.jsp</location>
</error-page>

I tried many ways to handle the exceptions, can any one help me in finding out a solution. The error i am getting when i try to handle these exceptions is as follows.

I am using JSF 1.2 and the server is websphere 8

The Console shows the Following Exception.

com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException

E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [/sc00/ErrorPage.jsp] in application [MembershipEligibilityScreensEAR]. Exception created : [java.lang.RuntimeException: FacesContext not found

My Error Page is in /WebContent/sc00/ErrorPage.jsp, ErrorPage.jsp has no backing bean associated with it.

Many solutions asked me to look at the URL path of Faces Servlet, In My web.xml the servlet-mapping is a follows

 <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

all the paths in my faces-config.xml refer to /FolderName/JspName and they work fine and they work fine even in Navigation.xml.

How can i navigate it to ErrorPage.jsp, Is there any way so that i can write a listener to this kind of problem

Sorry for posting too many redundant questions, i am new to JSF and i don't know the rules of StackOverflow, I apologize for the problem i have caused.

any solution would be appreciated.

解决方案

 java.lang.RuntimeException: FacesContext not found 

That will happen when you're requesting a JSP page containing JSF components through an URL which doesn't match the URL pattern of the FacesServlet (who is the one responsible for creating the FacesContext).

You need to change the error page location to match the URL pattern of the FacesServlet as definited in web.xml. Based on your duplicate questions on the subject, this is among others *.faces, so setting the error page location as follows should do, exactly as I suggested in a comment on your first question on the subject.

<location>/sc00/ErrorPage.faces</location>

这篇关于JSF 1.2异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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