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>
  • 相关阅读:
    LeetCode 1672. 最富有客户的资产总量
    LeetCode 455. 分发饼干
    Linux上安装docker并设置免sudo权限与国内镜像源
    Java后端期末复习
    Windows 10 家庭版开启本地安全策略 关闭管理员权限提升
    C语言中两种交换变量值方法的速度测试
    jQuery动态生成元素无法绑定事件的解决办法
    JQuery绑定事件处理动态添加的元素
    Socket通信服务端和客户端总结
    js传函数指针
  • 原文地址:https://www.cnblogs.com/wjx6270/p/12690232.html
Copyright © 2011-2022 走看看