我开始使用 JSF,但我有点迷失了。我正在开发一个 JSF 应用程序,并且有两个输入点。
有时我需要浏览器打开名为 mydata.xhtml 的页面,有时我需要打开名为 dataexchange.xhtml 的页面。
现在我已经完成了第一个,并且应用程序运行良好。我想我必须更改我的 web.xml 文件,不是吗?
我的web.xml是这样的。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.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/mydata.xhtml</welcome-file>
</welcome-file-list>
</web-app></pre>
最佳答案
我认为 web.xml 中没有 if-else
逻辑选项
<welcome-file-list>
<welcome-file>faces/mydata.xhtml</welcome-file>
<welcome-file>faces/dataexchange.xhtml</welcome-file>
</welcome-file-list>
如果您将这两个文件都放在欢迎文件列表中,容器将首先搜索 mydata.xhtml,只有在找不到时,容器才会搜索并返回 dataexchange。
或者,您可以拥有一个 DispatcherServlet (
Either some framework provided or custom servlet with load on startup 1
) 您可以从 servlet 返回您想要的 xhtml。
关于java - web.xml 在welcome-file-list 中有不同的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23800647/