我制作了一个名为Sport的简单应用程序。测试后,主页(index.xhtml)显示正确,URL为:
http://localhost:8080/Sport
当我单击导航菜单中的一个项目时,例如Teams,请求的页面( Teams .xhtml)正确显示,但URL看起来像这样:
http://localhost:8080/Sport/index.html;jsessionid=C9B3379254D6E21A6A2EA90775710108
之后,我点击另一个项目,例如体育场。页面体育场.xhtml显示,但URL是:
http://localhost:8080/Sport/teams.xhtml
这种行为继续下去。看起来URL总是比实际页面晚一步。
menu.xhtml:
...
<h:commandLink value="#{msgs.home}" action="home" />
<h:commandLink value="#{msgs.teams}" action="teams" />
<h:commandLink value="#{msgs.stadiums}" action="stadiums" />
...
faces-config.xml:
...
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
<redirect/>
</navigation-rule>
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>stadiums</from-outcome>
<to-view-id>/stadium.xhtml</to-view-id>
</navigation-case>
<redirect/>
</navigation-rule>
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>teams</from-outcome>
<to-view-id>/team.xhtml</to-view-id>
</navigation-case>
<redirect/>
</navigation-rule>
...
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>
<!-- Use Documents Saved as *.xhtml -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</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>
<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>
<!--<url-pattern>/faces/*</url-pattern>-->
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
我正在使用JSF2.2库(在NetBeans 7.4)。
什么好主意吗?
看起来它生成了错误的URL,但是这是JSF在导航上的默认操作。
下面的页面有一个关于JSF中的页面转发和页面重定向的很好的例子。
http://www.mkyong.com/jsf2/jsf-page-forward-vs-page-redirect/