JSF导航生成错误的URL
我制作了一个名为Sport的简单应用程序。测试时,主页(index.xhtml)显示正确,URL为:JSF导航生成错误的URL,url,netbeans,navigation,jsf-2.2,Url,Netbeans,Navigation,Jsf 2.2,我制作了一个名为Sport的简单应用程序。测试时,主页(index.xhtml)显示正确,URL为:http://localhost:8080/Sport 当我单击导航菜单中的某个项目(例如团队)时,请求的页面(Teams.xhtml)将正确显示,但URL如下所示:http://localhost:8080/Sport/index.html;jsessionid=C9B3379254D6E21A6A2EA9077571108 之后,我单击另一个项目,例如体育场。将显示页面stadiums.xht
http://localhost:8080/Sport
当我单击导航菜单中的某个项目(例如团队)时,请求的页面(Teams.xhtml)将正确显示,但URL如下所示:http://localhost:8080/Sport/index.html;jsessionid=C9B3379254D6E21A6A2EA9077571108
之后,我单击另一个项目,例如体育场。将显示页面stadiums.xhtml,但URL为:http://localhost:8080/Sport/teams.xhtml
这种行为还在继续。看起来URL总是比实际页面落后一步
菜单。xhtml:
...
<h:commandLink value="#{msgs.home}" action="home" />
<h:commandLink value="#{msgs.teams}" action="teams" />
<h:commandLink value="#{msgs.stadiums}" action="stadiums" />
...
...
<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>
...
<?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>
。。。
...
faces config.xml:
...
<h:commandLink value="#{msgs.home}" action="home" />
<h:commandLink value="#{msgs.teams}" action="teams" />
<h:commandLink value="#{msgs.stadiums}" action="stadiums" />
...
...
<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>
...
<?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>
。。。
*
家
/index.xhtml
*
体育场馆
/stadium.xhtml
*
团队
/team.xhtml
...
web.xml:
...
<h:commandLink value="#{msgs.home}" action="home" />
<h:commandLink value="#{msgs.teams}" action="teams" />
<h:commandLink value="#{msgs.stadiums}" action="stadiums" />
...
...
<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>
...
<?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>
javax.faces.PROJECT_阶段
发展
javax.faces.DEFAULT_后缀
.xhtml
javax.faces.CONFIG_文件
/WEB-INF/faces-config.xml
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.xhtml
30
index.xhtml
我正在使用JSF2.2库(在NetBeans 7.4中)。有什么想法吗?看起来它生成了错误的URL,但是这是默认的JSF导航操作 下面的页面有一个关于JSF中的页面转发和页面重定向的非常好的例子
重复和,顺便说一句,请停止阅读JSF 1.x目标书籍/教程/参考资料。那些通过命令链接进行的页到页导航操作和那些导航规则不再是JSF2.x了。关于这一切的最佳实践,请参见。谢谢您的回复,巴卢斯克。非常有用,但是我用GauravS在下面发布的链接解决了这个问题。谢谢,这对我帮助很大。我把标签放在标签外面。应该在里面。现在它起作用了:)