javax.faces.webapp.UIComponentClassicTagBase.setJspId 处的 java.lang.NullPointerException [英] java.lang.NullPointerException at javax.faces.webapp.UIComponentClassicTagBase.setJspId
问题描述
我已经阅读了本教程,它是一本电子书,我一直坚持将 JSP 页面部署到我的 tomcat 服务器,因为它是一个 jsp 页面,但它使用的是 JSF 标签,我已经把我的 javax.faces-2.1.13 jar 放在lib,哪里应该真正属于..
I have read this tutorials it's an ebook and I'm stuck at deploying the JSP page to my tomcat server by the way it's a jsp page but it's using JSF tags I already put my javax.faces-2.1.13 jar at the lib, where is should really belong to..
这是我的 JSP 页面标题 hello.jsp:
Here is my JSP page title 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>
这是我得到的堆栈跟踪错误:
And this is the stack trace error that I get:
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)
任何可以帮助我的人,我真的很感激.:)
Anyone that can help guys I really appreciate it. :)
推荐答案
java.lang.NullPointerException
at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1858)
此时 FacesContext
为 null
.这意味着 FacesServlet
没有完成它的工作.堆栈跟踪也证明了这一点;缺少 at javax.faces.webapp.FacesServlet.service()
行.
The FacesContext
is null
at that point. This means that the FacesServlet
didn't do its job. The stacktrace is also evidence of this; the line at javax.faces.webapp.FacesServlet.service()
is missing.
请求 URL 需要与 FacesServlet
的
匹配,正如您在 /WEB-INF/web.xml 中配置的那样
以便正确调用它.
The request URL needs to match the <url-pattern>
of the FacesServlet
as you've configured in /WEB-INF/web.xml
in order to properly invoke it.
所以,如果是例如
,那么你应该通过/hello.jsf
打开页面而不是浏览器地址栏中的 /hello.jsp
.
So, if it's for example <url-pattern>*.jsf</url-pattern>
, then you should open the page by /hello.jsf
instead of /hello.jsp
in browser address bar.
与具体问题无关,JSP 自 JSF 2.0 起不推荐.您应该放弃这种传统的视图技术,并着眼于它的继任者 Facelets.您应该绝对确保您没有阅读针对 JSF 1.x 而不是 JSF 2.x 的书籍/教程/资源.与 1.x 相比,JSF 2.x 中的很多事情都做了不同的事情,从长远来看,这只会导致初学者之间的混淆.
Unrelated to the concrete problem, JSP is deprecated since JSF 2.0. You should be discarding this legacy view technology and be looking at its successor Facelets. You should make absolutely sure that you aren't reading books/tutorials/resources targeted on JSF 1.x instead of JSF 2.x. A lot of things are done differently in JSF 2.x as opposed to 1.x, which would in long term only lead to confusion among starters.
- 找不到 http://java.sun.com/jsf/facelets 的标签库描述符
- 如何使用 JSF 2.0 Facelets 在 XHTML 中包含另一个 XHTML?
- 从 JSF 1.2 迁移到 JSF 2.0
这篇关于javax.faces.webapp.UIComponentClassicTagBase.setJspId 处的 java.lang.NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!