我有一个JSF项目,并且我已经有了一个工作正常的index.xhtml页面。当我尝试添加另一个XHTML页面时,由于某种原因,它没有连接到我的会话范围的托管bean。我在新页面中添加了代码,但它的工作方式与我的index.xhtml不同。我甚至复制并粘贴了索引中的代码,但它仍然不能工作。有什么想法吗?
下面是我在新页面中的一些代码:
Amount: <h:inputText value="#{transactionBean.amount}" style="color: Yellow; background: Teal;"/>
Price <h:inputText value="#{transactionBean.pricePaid}" style="color: Yellow; background: Teal;"/这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>发布于 2012-03-03 04:42:26
您已经将faces servlet映射到了/faces/*上,而不是*.xhtml上。这意味着您需要在URL中包含/faces路径,以便让faces servlet运行。
因此,您不应该通过以下方式打开页面
http://localhost:8080/SharePortfolioJSF/companies.xhtml
而不是通过
http://localhost:8080/SharePortfolioJSF/faces/companies.xhtml
然而,更好的方法是只使用*.xhtml作为faces servlet的URL模式,这样就不需要处理虚拟路径。
<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>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>(请注意,30分钟的<session-timeout>已经是默认值,只需删除它即可)
发布于 2012-03-03 04:41:35
从评论中:
您的第二个页面不是由faces servlet处理的。faces servlet的url模式是/faces/*。因此,所有请求都必须包含前缀/faces才能被servlet处理。
如果您使用以下URL调用您的页面,它应该会起作用:
http://localhost:8080/SharePortfolioJSF/faces/companies.xhtml
https://stackoverflow.com/questions/9539777
复制相似问题