web.xml
配置核心控制器dispatcherServlet
加载spring-servlet.xml的配置文件
<servlet>
<servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
spring-mvc.xml
视图解析器
增加前缀 后缀
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property> <property name="suffix" value=".jsp"></property>
增加对@Controller @RequestMapping 标签的支持
<context:component-scan base-package="cn.smbms.controller.user"></context:component-scan>
<mvc:annotation-driven></mvc:annotation-driven>Controller文件下类名前 @Controller 方法名前@RequestMapping(value="/dologin.html",method=RequestMethod.POST)或(“/user”)