以下是我的application-context.xml
<context:component-scan base-package="org.godfather"></context:component-scan>
<mvc:view-controller path="/main.do" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>
问题:如果我注释掉,<mvc:view-controller path="/main.do" />
则http://localhost:8181/tiles-app-1.1.1/header.do
url 有效,但如果没有注释掉,则 url 无效,No mapping found for HTTP request with URI [/tiles-app-1.1.1/header.do] in DispatcherServlet with name 'mytiles'
为什么会这样?
Web.xml
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/application-context.xml
</param-value>
</context-param>
<servlet>
<servlet-name>mytiles</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>mytiles</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
控制器
package org.godfather;
@Controller
public class AppointmentController {
@RequestMapping("/header")
public void get() {
System.out.println("get()");
}
提前致谢。