web.xml配置

名称:web.xml
目录:/webapp/WEB-INF/web.xml
内容:过滤器、Servlet


<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  
  <!-- 定位applicatioinContext.xml路径 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
 
  <filter>
      <filter-name>springEncoding</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>
      <init-param>
          <param-name>forceEncoding</param-name>
          <param-value>true</param-value>
      </init-param>
  </filter>
  
  <filter>
    <filter-name>openSessionInView</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>
  </filter>
  
  <filter>
      <filter-name>sessionFilter</filter-name>
      <filter-class>com.troyforever.example.filter.SessionFilter</filter-class>
  </filter>
  
  <filter-mapping>
      <filter-name>springEncoding</filter-name>
      <url-pattern>/*</url-pattern>
  </filter-mapping>
  
  <filter-mapping>
    <filter-name>openSessionInView</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  
    <filter-mapping>
      <filter-name>sessionFilter</filter-name>
      <url-pattern>/admin/*</url-pattern>
  </filter-mapping>  

  <!-- 加载applicationContext.xml配置文件 -->
    <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

   <servlet>
    <servlet-name>example</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  
  
  <servlet-mapping>
    <servlet-name>example</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  

</web-app>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 大家好,我是IT修真院深圳分院第1期学员,一枚正直纯洁善良的web程序员。今天给大家分享一下,修真院官网JAVA(...
    老菜菜阅读 4,044评论 0 1
  • 1. web.xml配置详解 <web-app> <!--指定WEB应用的名字--> <display-n...
    zhglance阅读 4,177评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,833评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,119评论 6 342
  • 有些事情,只能自己一个人过!不是每一个人给你的伤害都是应该的!也不是每一个看起来很好的意见都应该被采取,有些人,有...
    被关注的旧时光阅读 1,396评论 0 0

友情链接更多精彩内容