带有spring的web.xml中的欢迎文件无法正常工作? [英] welcome-file in web.xml with spring not working?

查看:139
本文介绍了带有spring的web.xml中的欢迎文件无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了spring-mvc servlet来匹配* .page 请求.我已经在web.xml中将 welcome-file-list 设置为index.page

I have setup my spring-mvc servlet to match *.page requests. I have setup the welcome-file-list in web.xml to be index.page

当我转到Web服务器的根目录时,此方法有效:

This works when I go to the root of my webserver:

http://me.com 确实重定向到了

http://me.com does get redirected to http://me.com/index.page correctly.

但是,当我使用subdirectoris时,它不会重定向:

However, it doesn't redirect when I use subdirectoris:

http://me.com/dashboard 不会 not 重定向到 http://me.com/dashboard/index.page

有什么方法可以使此映射正常工作吗?

Is there any way to get this mapping working?

我的web.xml文件(摘录):

My web.xml file (extract):

<welcome-file-list>
    <welcome-file>index.page</welcome-file>
</welcome-file-list>

<servlet-mapping>
    <servlet-name>spring-mvc</servlet-name>
    <url-pattern>*.page</url-pattern>
</servlet-mapping>

我的webdefault.xml(来自码头):

My webdefault.xml (from jetty):

    <init-param>
        <param-name>dirAllowed</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>welcomeServlets</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>redirectWelcome</param-name>
        <param-value>false</param-value>
    </init-param>

推荐答案

它仅适用于真实的物理目录,不适用于模拟目录结构的任意servlet映射.

It will work only for real, physical directories, not won't work for arbitrary servlet mappings simulating directory structure.

Spring MVC允许非常复杂的URL映射,因此您最好使用@RequestMapping

Spring MVC allows very complex URL mappings, so you'd better handle this scenario with @RequestMapping

这篇关于带有spring的web.xml中的欢迎文件无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆