SpringMVC默认首页设置


转:http://blog.csdn.net/white_smile/article/details/19151685

使用SpringMVC框架搭建Web,在web.xml中添加

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

发现不能识别首页,看来不是像Web工程一样进行简单的设置。

    SpringMVC使用拦截机制,需要进行Servlet映射,添加一个新的扩展名,总而言之,需要在web.xml中加入以下设置:

<servlet-mapping>  
    <servlet-name>springmvc</servlet-name>  
    <url-pattern>/index</url-pattern>  
</servlet-mapping> 

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

  根据SpringMVC机制,数据被封装成请求后会去寻找相应的控制器(controller),根据你在applicationContext.xml中的设置,寻找控制器的地址,比如:

<context:component-scan base-package="com.wisu.xitiancheng">  
    <context:exclude-filter type="regex" expression="com.wisu.xitiancheng.control.*"/>  
</context:component-scan>

在控制器中添加默认首页控制器,比如:

    /** 
    * 默认首页控制器 
    */  
    @RequestMapping("/index")  
    public String login(HttpServletRequest request, HttpServletResponse response){  
        return "index";  
    }  

 

 

使用SpringMVC框架搭建Web,在web.xml中添加

[html] view plain copy
  1. <welcome-file-list>  
  2.     <welcome-file>index.htm</welcome-file>  
  3. </welcome-file-list>  

发现不能识别首页,看来不是像Web工程一样进行简单的设置。

    SpringMVC使用拦截机制,需要进行Servlet映射,添加一个新的扩展名,总而言之,需要在web.xml中加入以下设置:

 

[html] view plain copy
  1. <servlet-mapping>  
  2.     <servlet-name>springmvc</servlet-name>  
  3.     <url-pattern>/index</url-pattern>  
  4. </servlet-mapping>  

[html] view plain copy
  1. <welcome-file-list>   
  2.     <welcome-file>index</welcome-file>   
  3. </welcome-file-list>  

    根据SpringMVC机制,数据被封装成请求后会去寻找相应的控制器(controller),根据你在applicationContext.xml中的设置,寻找控制器的地址,比如:

 

[html] view plain copy
  1. <context:component-scan base-package="com.wisu.xitiancheng">  
  2.     <context:exclude-filter type="regex" expression="com.wisu.xitiancheng.control.*"/>  
  3. </context:component-scan>  

    在控制器中添加默认首页控制器,比如:

 

[java] view plain copy
  1. /** 
  2. * 默认首页控制器 
  3. */  
  4. @RequestMapping("/index")  
  5. public String login(HttpServletRequest request, HttpServletResponse response){  
  6.     return "index";  
  7. }  
[java] view plain copy
  1. //根据返回的值通过视图解析器查找相应的页面返回给用户 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM