【问题标题】:web.xml with different files in welcome-file-listweb.xml 在welcome-file-list 中有不同的文件
【发布时间】:2014-05-22 07:41:35
【问题描述】:

我开始使用 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>

【问题讨论】:

    标签: java xml jsf jsf-2 web.xml


    【解决方案1】:

    我认为 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。

    【讨论】:

      猜你喜欢
      • 2016-11-28
      • 2017-04-20
      • 2012-11-07
      • 1970-01-01
      • 2017-08-19
      • 2014-08-31
      • 2019-01-03
      • 2015-11-27
      相关资源
      最近更新 更多