轉: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中添加
- <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";
- }
- //根據返回的值通過視圖解析器查找相應的頁面返回給用戶