入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

SpringMVC默认首页设置

创建时间:2014-02-13 投稿人: 浏览次数:14496

    使用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";
}
//根据返回的值通过视图解析器查找相应的页面返回给用户

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像