一、统一资源访问接口html
Resourcejava
二、实现类web
FileSystemResource 经过文件系统路径访问spring
ClassPathResource 经过classpath路径访问缓存
ServletContextResource 相对于web根目录路径访问服务器
三、工具类app
ResourceUtils 经过classpath:和file:资源前缀路径访问工具
一、FileCopyUtils编码
取代底层的文件操做url
二、PropertiesLoaderUtils
操做properties文件(文件要存放在classpath下,不然须要传入resource对象)
三、EncodedResource
对Resource进行编码处理
一、WebApplicationContextUtils
获取WebApplicatoinContext对象
二、WebUtils
封装了原始的Servlet API方法
一、延迟加载过滤器
<filter> <filter-name>hibernateFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping>
二、中文乱码过滤器
<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>
三、Web 应用根目录监听器
可经过System.getProperty("mu.root")或在properties中${mu.root}获取web应用程序根目录
<context-param> <param-name>webAppRootKey</param-name> <param-value>mu.root</param-value> </context-param> <listener> <listener-class> org.springframework.web.util.WebAppRootListener </listener-class> </listener>
四、Log4J 监听器
该监听器包含了WebAppRootListener的功能,因此配置了这个WebAppRootListener就不用配置了
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
注意:WebAppRootListener 和 Log4jConfigListener 都只能在Web应用部署后WAR 文件会解包的Web应用服务器上使用。
五、Introspector 缓存清除监听器
保证在 Web 应用关闭的时候释放与其相关的 ClassLoader 的缓存和类引用
<listener> <listener-class> org.springframework.web.util.IntrospectorCleanupListener </listener-class> </listener>
对html字符串进行编码和解码处理
htmlEscape(String input)
htmlUnescape(String input)
对变动进行条件判断,若是不符合将抛出异常
例如:
Assert.hasText
(str,”不能为空字符串”)
str不为null 且必须至少包含一个非空格的字符,不然抛出异常 java.lang.IllegalArgumentException: 不能为空字符串