我正在学习JSF并从Exadel.com获得帮助。我按照那里描述的步骤。
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>FBApp</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<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>
</web-app>
faces-config.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<navigation-rule>
<from-view-id>/pages/inputname.jsf</from-view-id>
<navigation-case>
<from-outcome>greeting</from-outcome>
<to-view-id>/pages/greeting.jsf</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>personBean</managed-bean-name>
<managed-bean-class>com.fbapp.bean.PersonBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
的index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>index</title>
</head>
<body>
<jsp:forward page="faces/pages/inputname.jsf" />
</body>
</html>
inputname.jsp:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<title>enter your name page</title>
</head>
<body>
<f:view>
<h1>
<h:outputText value="JSF KickStart"/>
</h1>
<h:form id="helloForm">
<h:outputText value="Tell us your name"/>
<h:inputText value="#{personBean.personName}" />
<h:commandButton action="greeting" value="Say Hello" />
</h:form>
</f:view>
</body>
</html>
现在存在的差异是:
<jsp:forward page="faces/pages/inputname.jsf" />
,Exadel使用了<jsp:forward page="/pages/inputname.jsf" />
<url-pattern>/faces/*</url-pattern>
,他们使用了:
<url-pattern>*.jsf</url-pattern>
jar库是:
在JBoss 4.2.2GA中(为JSF定制)我将战争部署为运行但当我尝试转到URL http://localhost:8080/FBApp/时,页面呈现为:
实际上是inputname.jsf的代码。我做错了什么?任何信息都会很明显。
谢谢和问候。
编辑: 代码已根据BalusC的指示进行了更改。现在我得到异常和stacktrace:
19:34:04,244 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:162)
at org.apache.jsp.pages.inputname_jsp._jspx_meth_f_005fview_005f0(inputname_jsp.java:104)
at org.apache.jsp.pages.inputname_jsp._jspService(inputname_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:636)
19:34:04,245 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:162)
at org.apache.jsp.pages.inputname_jsp._jspx_meth_f_005fview_005f0(inputname_jsp.java:104)
at org.apache.jsp.pages.inputname_jsp._jspService(inputname_jsp.java:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:636)
答案 0 :(得分:8)
如果您为实际 JSP文件提供.jsf
扩展名,则会发生这种情况。换句话说,您的网络内容文件夹中没有inputname.jsp
文件,但实际上一个inputname.jsf
文件。这是错的。这些JSP文件应保留.jsp
扩展名,以便JspServlet
处理。否则,这些文件根本不会被解析为JSP,最终会以webbrowser中的纯文本结尾。
您已将FacesServlet
的网址格式更改为/faces/*
,而不是(推荐的更多)*.jsf
。因此,您应该将教程中的所有网址从/foo.jsf
更改为/faces/foo.jsp
,也可以在转发/包含和导航案例中。您应该不更改为/faces/foo.jsf
并在实际文件中使用错误的扩展名。
无关:您是否有任何特殊原因要阅读6年历史的JSF 1.1目标教程而不是更新的JSF 2.0目标教程? JSF 1.1拥有如此多的disadvantages,并且自1.5年前以来,Facelets也继承了传统的JSP。
更新:
@cularis这是我的第一个项目。我得到了
java.lang.ClassCastException: com.sun.faces.application.ApplicationAssociate cannot be cast to com.sun.faces.application.ApplicationAssociate
,我在这里找到了这个问题的解决方案并按照说法完成了,问题解决了。我正在使用JBoss 4.2.2和JSF 1.2
如果运行时类路径被不同版本化的JSF库污染,则会发生此异常。 JBoss已经内置了JSF,因此您不应该在webapp的/WEB-INF/lib
文件夹中提供JSF库。如果它是不同的版本,它可能会与上述异常相冲突。
更新2 :
java.lang.NullPointerException at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:162)
嗯,这是一个讨厌的,我以前没见过。我敢打赌它只是因为类路污染造成的。 JBoss 4.2.x已经内置了JSF 1.2和JSTL 1.1。请从/WEB-INF/lib
中删除jsf * .jar和jstl * .jar库。另请从<context-param>
删除所有与JSF相关的<listener>
和web.xml
个人。你到目前为止已经是所有的JSF 1.2默认值。它可能会或可能不会解决您的具体问题,但至少应该将噪音降至最低。让我知道。
更新3 :
我已从web.xml中删除了jar和条目,并在jboss-4.2.2.GA/server/default/deploy/jboss-web.deployer/conf/web.xml中取消注释了注释行,现在我我得到了
java.lang.RuntimeException: Cannot find FacesContext
。但是之前的问题已经解决了
好多了。 Cannot find FacesContext
错误有一个简单的原因:FacesServlet
尚未被调用。因此,请求或转发网址根本不符合FacesServlet
的网址格式。假设您仍然将FacesServlet
映射到/faces/*
的网址格式,并且您的网络内容中包含实际/pages/inputname.jsp
文件,那么您的所有index.jsp
应包含的是以下单行(是的,除去所有不相关的HTML)
<jsp:forward page="faces/pages/inputname.jsp" />
这样只需调用
应该有效。如果它由于某种原因(让我知道),那么至少打电话
必须工作。
更新4 :
嗯,这对我来说也是新的。您的解决了FacesContext异常,但现在它正在抛出
javax.faces.FacesException: java.net.MalformedURLException: Path faces-config.xml does not start with a "/" character.
web.xml
现在如何?这表明您的javax.faces.CONFIG_FILES
上下文参数的值为faces-config.xml
。尝试将值javax.faces.CONFIG_FILES
的{{1}}上下文参数放回/WEB-INF/faces-config.xml
。也许JBoss中使用的JSF 1.2 impl有一些与此相关的bug。
答案 1 :(得分:1)
如果你是初学者,你应该真正开始阅读JSF 2.0,而不是旧的弃用1.1。 有很多与JSF相关的书籍。 最好成绩