zoukankan      html  css  js  c++  java
  • web.xml整合spring springmvc

    <?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上下文配置-->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/spring.xml</param-value>
    </context-param>

    <!--1,Spring监听器-->

    <!--1.1 web容器启动时触发的监听器,在web容器启动时,加载类似上面"content-param"标签指定的配置文件-->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!--1.2 http请求的监听器:如果需要配置request,session,globalSession作用域的bean,则需要配置以下监听器-->
    <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <!--2,springmvc的dispatcherServlet-->
    <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <!--是否使用异步处理(3.0新特性),提高并发能力-->
    <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!--3,对静态资源的访问交给defaultServlet处理,放在dispatcherServlet的mapping之前,不需要经过dispatcherServlet来提高性能-->
    <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
    </servlet-mapping>

    <!--4,乱码问题处理-->
    <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <async-supported>true</async-supported>
    <!--初始化编码方式-->
    <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param>

    </filter>
    <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    </web-app>
  • 相关阅读:
    一个可以代替冗长switch-case的消息分发小框架
    [JCIP笔记](五)JDK并发包
    [JCIP笔记](四)踩在巨人的肩上
    [JCIP笔记] (三)如何设计一个线程安全的对象
    工作两年的五个感想
    [JCIP笔记] (二)当我们谈线程安全时,我们在谈论什么
    [JCIP笔记] (一)多线程的起源
    每天进步一点点------CORDIC (一)
    每天进步一点点------Alpha半透明图形叠加算法Matlab+Verilog实现
    每天进步一点点------Altium Designer Rules规则详解
  • 原文地址:https://www.cnblogs.com/wjx6270/p/12690232.html
Copyright © 2011-2022 走看看