spring学习笔记一 spring web.xml文件配置详解
来源:互联网 发布:千锋java视频全套教程 编辑:程序博客网 时间:2024/06/13 07:10
1、spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name)
<filter> <filter-name>characterEncodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>
2、自动加载类
在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制,自动加载的容器中去,在web项目中,配置文件加载到web容器中进行解析,目前,spring提供了两种加载器,以供web容器的加载:一种是ContextLoaderListener,另一种是ContextLoaderServlet。这两种在功能上完全相同,只是一种是基于Servlet2.3版本中新引入的Listener接口实现,而另一种是基于Servlet接口实现,以下是这两种加载器在web.xml中的时机配置应用:
第一种:
<listener> <listener-class>org.springframework.context.ContextLoaderListener</listener-class></listener>
ContextLoaderListener是Spring的监听器,它的作用就是启动Web容器时,自动装配ApplicationContext的配置信息。因为它实现了ServletContextListener这个接口,在web.xml配置这个监听器,启动容器时,就会默认执行它实现的方法。
另一种:
<servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup></servlet>
通过上面的配置,web容器会自动加载applicationcontext.xml初始化。
如果需要指定配置文件的位置,可通过context-param加以指定:
<context-param> <param-name>contextConfigLocation</param-name> <!-- <param-value>classpath*:config/applicationContext.xml</param-value> --> <param-value>/WEB-INF/myApplicationContext.xml</param-value></context-param>
之后,可以通过
WebApplicationContextUtils.getWebApplicationContext方法在web应用中获取applicationcontext的引用。
阅读全文
0 0
- spring学习笔记一 spring web.xml文件配置详解
- 【spring学习笔记一】使用xml文件配置bean
- 【spring MVC学习一】web.xml中的spring的配置
- spring配置 web.xml详解
- Spring MVC的web.xml文件配置详解
- spring mvc学习(一)之web.xml配置
- Spring 学习笔记(一) XML配置方法
- 5 Spring 入门 web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- web.xml中spring/springmvc配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- Spring MVC的web.xml配置详解
- SpringCloud-Learning -作者:翟永超
- oracle中数据类型number(9,2)的意思
- mysql将一张表的数据内容update至另外一张表
- HTML学习---------1.9 引用标签<q>和<blockquote>
- leetcode刷题——(1)
- spring学习笔记一 spring web.xml文件配置详解
- 第13章练习
- 简单表格-今日小说排行榜
- GroupMetadataManager分析
- Java JFrame常用的布局
- mysql查询所有记录,并去掉重复的记录
- App的启动过程(4)在WMS中注册窗口
- HMM隐马尔可夫模型(HMM)攻略
- centos6.9 oracle安装需注意的问题