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


    <?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>
  • 相关阅读:
    OSI安全体系结构
    PHP 二维数组根据相同的值进行合并
    Java实现 LeetCode 17 电话号码的字母组合
    Java实现 LeetCode 16 最接近的三数之和
    Java实现 LeetCode 16 最接近的三数之和
    Java实现 LeetCode 16 最接近的三数之和
    Java实现 LeetCode 15 三数之和
    Java实现 LeetCode 15 三数之和
    Java实现 LeetCode 15 三数之和
    Java实现 LeetCode 14 最长公共前缀
  • 原文地址:https://www.cnblogs.com/550410638boke/p/11049721.html
Copyright © 2020-2023  润新知