Spring-Web MVC框架是圍繞 DispatcherServlet 設計的,DispatcherServlet 用來處理所有的 HTTP 請求和響應。
1、映射你想讓 DispatcherServlet 處理的請求,通過使用在 web.xml 文件中的一個 URL 映射。
2、web.xml 文件將被保留在你的應用程序的 WebContent/WEB-INF 目錄下。在初始化 DispatcherServlet 時,該框架將嘗試加載位於該應用程序的 WebContent/WEB-INF 目錄中文件名為 xxx-servlet.xml
的應用程序內容。
spring-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <description>Spring-web MVC配置</description> <!-- InternalResourceViewResolver 將使用定義的規則來解決視圖名稱。 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/" /> <property name="suffix" value=".jsp" /> </bean> </beans>