这个是mvc.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
">
<!-- 静态资源放行 -->
<mvc:default-servlet-handler/>
<!-- 开启对注解的支持-->
<mvc:annotation-driven></mvc:annotation-driven>
<!-- 开启扫描包 的支持-->
<mvc:context-scan base-package="cn.hk"></mvc:context-scan>
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="profix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
这个是web.xml
<?xml version="1.0" encoding="UTF-8"?>
day039-springMvc01
<!-- 配置前端控制器 -->
<servlet>
<servlet-name>Dispatcher</servlet-name>
<!-- webmvc包 -->
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 加载Springmvc的配置文件 -->
<init-param>
<!-- 参数名:不能乱写 上下文配置文件的路径 -->
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-mvc.xml</param-value>
</init-param>
<!-- 提前实例化 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<!-- <url-pattern>*.do</url-pattern> -->
<!-- 匹配所有请求:达到控制器的请求,html,css,imgs,jsp ,一般使用在过滤器中-->
<!-- <url-pattern>/*</url-pattern> -->
<!-- 匹配所有请求:达到控制器的请求,html,css,imgs 但是jsp不拦截 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--
前端控制器配置问题:
1.<param-name>contextConfigLocation</param-name>的名字容易出问题
2.classpath:applicationContext-mvc.xml - 项目中配置文件的位置和名称对应起来
不要抄代码
-->
<!-- 配置过滤器:解决post请求的中文乱码问题【默认服务器开启的时候就实例化了】 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<!-- web包 -->
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<!-- 所有请求 -->
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/jsp/controller.jsp</welcome-file>
</welcome-file-list>