SpringMVC默认欢迎页面的问题

1.默认tomcat容器的默认页面。

file-list>
    file>index.jspfile>
    file>index.htmlfile>
file-list>

这种方式适合访问静态的页面(也包括JSP)或者说是没有任何参数的页面。

2.SpingMVC配置控制器的代码

  1. web.xml配置
    
    <servlet>
        <servlet-name>MVC DispatcherServletservlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
        
        <init-param>
            
            <param-name>contextConfigLocationparam-name>
            
            <param-value>classpath:springmvc-context.xmlparam-value>
        init-param>
        <load-on-startup>1load-on-startup>
    servlet>

    
    <servlet-mapping>  
      <servlet-name>MVC DispatcherServletservlet-name>  
      <url-pattern>/indexurl-pattern>  
    servlet-mapping>
    <servlet-mapping>
        <servlet-name>MVC DispatcherServletservlet-name>
        
        <url-pattern>*.dourl-pattern>
    servlet-mapping>


    <welcome-file-list>
        <welcome-file>indexwelcome-file>
    welcome-file-list>

2.控制器中添加默认首页控制器

    @RequestMapping("/index")
    public String homepage(Model model){
        model.addAttribute("indexMsg", "hello,this is index.jsp form homepage/index.do");
        System.out.println("this is homepage!!!");
        return "index";
    }

3. 默认页跳转

1.web.xml配置

file-list>
    file>index.jspfile>
file-list>

2.index.jsp页面跳转到Controller

<jsp:forward page="/index">jsp:forward>

你可能感兴趣的:(spring-mvc,spring,mvc)