web.xml配置
<servlet>
<servlet-name>annomvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/annomvc-servlet.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>annomvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
annomvc-servlet.xml配置
<context:annotation-config />
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="com.svs.master.controller" />
<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/csy/page/" p:suffix=".htm" />
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="utf-8" />
controller类
@Controller@RequestMapping(value = "/userlogin.do")
public class UserLoginController {
@RequestMapping(params="method=login", method = RequestMethod.POST)
public String userLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { //...方法内容 }}
页面请求
<form method="post" action="userlogin.do?method=login" >
后台错误
20:45:52,098 DEBUG DispatcherServlet:693 - DispatcherServlet with name 'annomvc' processing POST request for [/test/csy/page/userlogin.do]
20:45:52,098 WARN PageNotFound:947 - No mapping found for HTTP request with URI [/test/csy/page/userlogin.do] in DispatcherServlet with name 'annomvc'
20:45:52,098 DEBUG DispatcherServlet:674 - Successfully completed request