zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    洛咕 P2403 [SDOI2010]所驼门王的宝藏
    洛咕 P2480 [SDOI2010]古代猪文
    洛咕 P2447 [SDOI2010]外星千足虫
    CF618F Double Knapsack 构造、抽屉原理
    Educational Codeforces Round 62
    CF908G New Year and Original Order 数位DP
    CF833D Red-Black Cobweb 点分治、树状数组
    Codechef CNTL Counting is life 生成函数
    LOJ2527 HAOI2018 染色 生成函数、二项式反演、NTT
    Luogu4916 魔力环 莫比乌斯反演、组合、生成函数
  • 原文地址:https://www.cnblogs.com/550410638boke/p/11049721.html
Copyright © 2011-2022 走看看