JAVA-Spring WebSite for Eclipse for XML 設定
Web.xml 設定
- 在
<context-param>
把mvc-config.xml
設定在contextConfigLocation1
2
3
4<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-config.xml</param-value>
</context-param> - 在設定
<listener>
1
2
3<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>P.S. 有在
<context-param>
設定contextConfigLocation,就要設定<listener>
For MVC
在
<servlet>
設定 DispatherServlet,建立前端控制器(front controller)1
2
3
4
5
6
7
8
9<servlet>
<servlet-name>translator</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>當
contextConfigLocation
尚未設定時,預設會讀取Servlet名稱- servlet.xml
在
<servlet-mapping>
設定 Controller條件1
2
3
4<servlet-mapping>
<servlet-name>translator</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>流程
- client request
- servlet-mapping 驗證 url,是否有符合
- 連結到 mapping 的 dispatcherServlet
- 根據 dispatcher-servlet.xml 連接到 Controller