首页 > 编程语言 > 详细

spring mvc核心监听器及解决中文乱码的解析器

时间:2019-06-19 10:36:28      阅读:138      评论:0      收藏:0      [点我收藏+]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">

<!--spring 的核心监听器作用:在web容器(tomcat)启动的时候,创建spring的工厂类对象,把该对象绑定到web容器的上下文(环境)
中。
之前我们使用spring 框架,第一件事都是创建工厂类对象:
ApplicationContext context = new ClassPathXmlApplciationContext("applicationContext.xml");
我们现在使用的是web项目,需不需要创建工厂类对象了?需要创建。
什么时候创建工厂类对象。工厂类对象只需要创建一个就够了,在项目启动的时候创建比较合适。
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!---
手动指定spring 的主配置文件的位置和名称,如果不指定该参数,则spring会默认从WEB-INF/applicationContext.xml
我们之前习惯把spring 的主配置文件放到src下面,所以一般会指定此项。
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<!--配置spring mvc的前端控制器
作用:拦截指定的请求,交给spring mvc框架进行处理
-->
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--指定spring mvc的主配置文件的位置和名称
如果不指定该参数,spring 会默认从WEB-INF/下加载 [servlet的name]-servlet.xml
针对这个例子,生成的配置文件名称就spring-mvc-servlet.xml
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<!--拦截所有.do结尾的请求,交给spring mvc 处理,如果要拦截所有请求 可以写/*-->
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!--解决中文乱码的解析器-->
<filter>
<filter-name>characterEncodingFilter</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>

</web-app>

spring mvc核心监听器及解决中文乱码的解析器

原文:https://www.cnblogs.com/550410638boke/p/11049721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!