javax.faces.webapp.UIComponentClassicTagBase.setJspId中的java.lang.NullPointerException

时间:2012-10-23 14:01:36

标签: jsp jsf

我已经阅读了这个教程,这是一本电子书,我一直坚持将JSP页面部署到我的tomcat服务器,就像它是一个jsp页面一样但是它使用的是JSF标签我已经把我的javax.faces-2.1.13 jar放到了lib,应该属于哪个..

这是我的JSP页面标题hello.jsp:

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>

<html>
<head>
<title>JSF In Action</title>
</head>
<body>
<f:view>
    <h:form id="welcome-form">
        <h:outputText id="welcomeOutput" value="Welcome to JavaServer Faces!" style="font-family: Arial, Sans-serif; font-size: 24; color: green;" />
        <p><h:message id="error" for="helloInput" style="color: red;" /></p>

        <p><h:outputLabel for="helloInput">
            <h:outputText id="helloInputLabel" value="Enter Number of Controls to Display:" />
        </h:outputLabel>
        <h:inputText id="helloInput" value="#{ helloBean.numcontrol }" required="true">
            <f:validateLongRange minimum="1" maximum="500" />
        </h:inputText></p>

        <p><h:panelGrid id="controlPanel" binding="#{ helloBean.controlPanel }" columns="20" border="1" cellspacing="0">
        </h:panelGrid></p>
        <h:commandButton id="redisplaycommand" type="submit" value="Redisplay" actionListener="#{ helloBean.addControl }" />
        <h:commandButton id="goodbyecommand" type="submit" value="GoodBye" action="#{ helloBean.goodbye }" immediate="true" />
    </h:form>
</f:view>
</body>
</html>

这是我得到的堆栈跟踪错误:

 SEVERE: Servlet.service() for servlet [jsp] in context with path [/SampleJSF1] threw exception [An exception occurred processing JSP page /hello.jsp at line 5

2: <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
3: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
4: 
5: <f:view>
6: <html>
7: <head>
8: <title>


Stacktrace:] with root cause
java.lang.NullPointerException
    at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1858)
    at org.apache.jsp.hello_jsp._jspx_meth_f_005fview_005f0(hello_jsp.java:126)
    at org.apache.jsp.hello_jsp._jspService(hello_jsp.java:100)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

任何可以帮助我的人我真的很感激。 :)

2 个答案:

答案 0 :(得分:7)

java.lang.NullPointerException
    at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1858)

此时FacesContextnull。这意味着FacesServlet没有完成其工作。堆栈跟踪也证明了这一点;缺少第at javax.faces.webapp.FacesServlet.service()行。

请求网址需要与您在<url-pattern>中配置的FacesServlet的{​​{1}}相匹配才能正确调用它。

因此,如果它是/WEB-INF/web.xml,那么您应该在浏览器地址栏中按<url-pattern>*.jsf</url-pattern>而不是/hello.jsf打开该页面。


对于具体问题

无关,自JSF 2.0以来,JSP已被弃用。您应该放弃这种传统的视图技术,并关注它的后续Facelets。你应该确保你没有阅读针对JSF 1.x而不是JSF 2.x的书籍/教程/资源。很多事情在JSF 2.x中都有所不同,而不是1.x,这在长期内只会导致初学者之间的混淆。

另见:

答案 1 :(得分:0)

要解决此问题,请执行以下给定步骤:

  1. 转到项目属性
  2. 项目面孔
  3. 检查javaServer Faces
  4. 单击所需的进一步配置
  5. 在JSF实现库中,选择:禁用库配置
  6. 应用