博主首页

web.xml配置解释

复制代码
<?xml version="1.0" encoding="UTF-8"?>
 <web-app version="3.1" 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_3_1.xsd">
//以上为web.xml头信息,
复制代码
 //让web容器初始化的时候初始化这些配置,*号代表通配符,会在根目录下和jar包里找
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:applicationContext.xml classpath:applicationContext-quartz.xml classpath:applicationContext-security.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
复制代码

复制代码
复制代码
 //eclipse自带的字符编码过滤,打开web.xml,点到Tree ,选择web.xml右击新建Filte
//搜索 CharacterEncodingFilter

//<init-param>这个标签代表在这里过滤器的范围内,初始化的时候初始化该值,然后在这个过滤器里进行设值进去
<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>
复制代码
复制代码
//serlet 的配置 ,会拦截到url-pattern这个值的请求   
<servlet> <servlet-name>UploadServlet</servlet-name> <servlet-class>com.ecar.mp.servlet.UploadServlet</servlet-class> <init-param> <param-name>filepath</param-name> <param-value>upload</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>UploadServlet</servlet-name> <url-pattern>/upload</url-pattern> </servlet-mapping>
复制代码
复制代码
    //前端控制器;springmvc的入口,*.do所有以.do结尾的请求都会被拦截
  <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
复制代码
//配置服务启动以后初始化的页面或者请求路径
<welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list>

 此配置是整合spring,springmvc的配置,整体介绍就是让web容器初始化的时候,去初始化spring容器;

以及springmvc的入口DispatcherServlet 

 

posted @   笑~笑  阅读(471)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示