Java的Filter 一:(转载)
关键字: filter
过滤器Filter也具有生命周期:init()->doFilter()->destroy(),由部署文件中的filter元素驱动。在servlet2.4中,过滤器同样可以用于请求分派器,但须在web.xml中声明,<dispatcher>INCLUDE或FORWARD或REQUEST或ERROR</dispatcher>该元素位于filter-mapping中。
一、批量设置请求编码
Java代码
public class EncodingFilter implements Filter {
private String encoding = null;
public void destroy() {
encoding = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String encoding = getEncoding();
if (encoding == null){
encoding = "gb2312";
}
request.setCharacterEncoding(encoding);// 在请求里设置上指定的编码
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
this.encoding = filterConfig.getInitParameter("encoding");
}
private String getEncoding() {
&nbs
相关文档:
package com.fanxing.neibulei;
/**
*
* @author xiaxiaorui
*
*泛型 受限泛型
*http://developer.51cto.com/art/200909/153983.htm
*/
class Info2<T>
{
private T var; // 定义泛型变量
public T getVar() {
return var;
}
public void setVar(T var) {
this.var = var;
}
......
两种形式:
1, 饿汉式单例类
public class Singleton {
private Singleton(){}
//在自己内部定义自己一个实例,是不是很奇怪?
//注意这是private 只供内部调用
private static Singleton instance = new Singleton();
//这里提供了一个供外部访问本class的静态方法,可以直接访问
p ......
SAMPLE:
import java.util.Properties;
Properties props=System.getProperties(); //获得系统属性集
String osName = props.getProperty("os.name"); //操作系统名称
String osArch = props.getPropert ......
java中的字符串也是一连串的字符。但是与许多其他的计算机语言将字符串作为字符数组处理不同,Java将字符串作为String类型对象来处理。将字符串作为内置的对象处理允许Java提供十分丰富的功能特性以方便处理字符串。下面是一些使用频率比较高的函数及其相关说明。
substring()
它有两种形式,第一种是:String substring ......