Spring mvc 4 中的默认 Jsp

Default Jsp in Spring mvc 4

在 Spring mvc 中,我们如何设置默认的 jsp 页面,即,一旦我们 运行 服务器上的项目,默认的 jsp 页面就会出现在浏览器中,就像在 jsf 中一样,我们可以使用 web.xml 中的以下代码实现它:

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

spring也一样,

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

您可以在 web.xml 中设置。但是您应该在 web-inf 之外设置 abc.jsp 以使其对浏览器可见。

另见:

  • How to configure welcome file list in web.xml

在使用 spring 时,您也可以在 web.xml

中提及相同内容
   <welcome-file-list>
         <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>

如何添加指向 index.jsp 的默认控制器?

@RequestMapping(value = "/", method = GET)
public String index() {
   return "index";
}

p.s。您是否指定了视图解析器?