zoukankan      html  css  js  c++  java
  • springMVC访问根路径问题

    当web.xml没有配置欢迎页:如下

    <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>

    此情况下,web服务器会有缺省的配置如下:可以修改

    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    假设我们的项目域名是www.**.com,此时默认会在项目目录下找index.html...等默认的欢迎页.项目路径下没有这些页面,会报404错误.

    如何设置SpringMVC 对根路径进行拦截?

    1.在web.xml中加入

        <welcome-file-list>  
            <welcome-file></welcome-file>  
        </welcome-file-list>  

    此时,web服务器就知道,根路径不要web服务器来处理,而是由程序自身来处理。

    然后在spring的配置文件中加入<mvc:view-controller path="/" view-name="forward:/index"/> :表示当访问主页时自动转发到index控制器 

    <mvc:view-controller path="/" view-name="login/login"/>  :表示跳转到login.jsp页面

  • 相关阅读:
    google浏览器切换成中文
    Python 进阶篇
    Linux 命令
    Linux
    Linux
    Linux
    Linux--shell脚本之文本处理工具
    Linux--shell脚本之正则表达式
    Linux
    Linux
  • 原文地址:https://www.cnblogs.com/2nao/p/7251143.html
Copyright © 2011-2022 走看看