default-action-ref 和 welcome-file-list 标签的区别

    技术2026-05-07  3

    default-action-ref 标签是 struts.xml 中的标签,意思是默认的动作引用,可以理解为当没有相应的 action 对应是,调用这个 action 引用,如下:

    1: <default-action-ref name="index" />

    上面这段代码意味着如果在地址栏中输入的 action 不存在,即调用 index 这个 action。

    但是,如果我们在地址栏中不指明 action ,即日常的访问主页的操作,通过  default-action-ref   标签是不能达到效果的,这个标签仅仅作用于地址栏存在 action 但是找不到相应 action 的情况下。

    那么如何达到像平常的那样访问主页的操作呢?我们就需要在 web.xml 中配置了。

    welcome-file 是 web.xml 中的标签,是  welcome-file-list 标签的子标签,顾名思义,是对欢迎页面的指定:

    1: <welcome-file-list> 2: <welcome-file>index</ welcome-file> 3: </ welcome-file-list>   当我们在 web.xml 中如是配置的话,我们就可以像访问主页一样直接定位到 index action 了。

    既然是 list ,当然就可以在内部定义多个 标签,当出现多个 标签的时候,又是如何定位的呢?

    1: <welcome-file-list> 2: <welcome-file>index1</ welcome-file> 3: <welcome-file>index2</ welcome-file> 4: <welcome-file>index3</ welcome-file> 5: <welcome-file>index4</ welcome-file> 6: </ welcome-file-list>

    我们可以在 中定义多个 标签,当浏览器发来请求的时候,服务器会根据 welcome-file-list 标签下的 标签进行遍历,一旦得到存在的 就立即 forward 到这个 。

    最新回复(0)