我正在使用MyFaces 1.2和WAS 7.0以及Myeclipse Blue 10.7。 我收到以下错误。 我已经彻底研究了互联网,但无济于事。 日志并不多。 MyEclipse没有像IBM RAD那样的JSF跟踪调试实用程序。
[8/8/13 10:41:19:447 EDT] 00000018 webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[/sui_index.jsp]: java.lang.NullPointerException at org.apache.myfaces.taglib.core.ViewTag.doStartTag(ViewTag.java:75) at com.ibm._jsp._sui_5F_welcome._jspx_meth_f_view_0(_sui_5F_welcome.java:755) at com.ibm._jsp._sui_5F_welcome._jspService(_sui_5F_welcome.java:121) at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99) at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1664) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:940) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:503)I am using MyFaces 1.2 with WAS 7.0 and Myeclipse Blue 10.7. I am getting the following error. I have researched Internet pretty thoroughly but to no avail. Logs don't present much. MyEclipse does not have JSF trace debug utility like IBM RAD.
[8/8/13 10:41:19:447 EDT] 00000018 webapp E com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[/sui_index.jsp]: java.lang.NullPointerException at org.apache.myfaces.taglib.core.ViewTag.doStartTag(ViewTag.java:75) at com.ibm._jsp._sui_5F_welcome._jspx_meth_f_view_0(_sui_5F_welcome.java:755) at com.ibm._jsp._sui_5F_welcome._jspService(_sui_5F_welcome.java:121) at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99) at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1664) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:940) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:503)最满意答案
当您通过请求URL打开包含JSF组件的JSP页面时,通常会出现此异常,该请求URL与FacesServlet的URL模式不匹配。 基本上,JSP页面中的JSF组件期望FacesContext可以使用FacesContext#getCurrentInstance() 。 但是,它返回null ,最终导致此NullPointerException 。
请注意,堆栈跟踪也没有提供正确调用FacesServlet任何提示。 调用直接转到容器自己的JSP servlet,在Websphere的情况下是HttpJspBase ,而不是JSF自己的FacesServlet 。
为了解决这个问题,只需在web.xml查看FacesServlet映射到的URL模式。 在JSF 1.x中,这通常是*.jsf或者*.faces或者很可能是/faces/* 。 一旦你想到这一点,只需确保请求URL(如浏览器的地址栏中所示)与该URL模式完全匹配。 所以,而不是例如
http://example.com/context/sui_index.jsp
你应该根据实际的映射使用其中之一
http://example.com/context/sui_index.jsf
要么
http://example.com/context/sui_index.faces
要么
http://example.com/context/faces/sui_index.jsp
无论哪种方式,这样都可以调用FacesServlet并且能够按照JSP页面中的JSF组件的预期正确准备FacesContext 。
也可以看看:
JSF Facelets:有时我看到URL是.jsf,有时是.xhtml。 为什么?This exception is typical when you open a JSP page containing JSF components by a request URL which does not match the URL pattern of the FacesServlet. Basically, the JSF components in the JSP page are expecting to the FacesContext to be available by FacesContext#getCurrentInstance(). However, it returned null which in turn ultimately caused this NullPointerException.
Note that the stack trace also doesn't give any hint that the FacesServlet is properly been called. The call went directly to the container's own JSP servlet, which is HttpJspBase in case of Websphere, instead of JSF's own FacesServlet.
In order to sovle this problem, just look in the web.xml on which URL pattern the FacesServlet is been mapped. In JSF 1.x, this is usually *.jsf or maybe *.faces or very maybe /faces/*. Once you figured that, just make sure that the request URL, as you see in browser's address bar, matches exactly that URL pattern. So, instead of for example
http://example.com/context/sui_index.jsp
you should depending on the actual mapping be using either
http://example.com/context/sui_index.jsf
or
http://example.com/context/sui_index.faces
or
http://example.com/context/faces/sui_index.jsp
Either way, this way the FacesServlet will be invoked and be able to properly prepare the FacesContext as expected by the JSF components in the JSP page.
See also:
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?更多推荐
发布评论