SpringMVC,Spring,Mybatis整合中web.xml配置

2025-05-22 16:41:18

1、配置Spring相关配置,启动Spring的容器<!-- 启动Spring的容器 --><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value></context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>

SpringMVC,Spring,Mybatis整合中web.xml配置

3、在web.xml中配置springmvc的前段控制器,拦截所有的请求<ser箪滹埘麽vlet> <servlet-name&爿讥旌护gt;dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>

SpringMVC,Spring,Mybatis整合中web.xml配置

5、配置SpringMVC字符编码过滤器:<filter> <filter-name>characterEn艘早祓胂codingFilter</filter-name> <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>

SpringMVC,Spring,Mybatis整合中web.xml配置

7、注意,过滤器是有先后的,一定要把字符编码过滤器放在最前面。

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢