charsetencodingfilter.java

来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· Java 代码 · 共 42 行

JAVA
42
字号
package com.sztheater.framework.web;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class CharsetEncodingFilter implements Filter{
 private FilterConfig       _filterConfig = null;
	private HttpServletRequest _httpRequest  = null;
	HttpServletResponse        _httpResponse = null;
	HttpSession                _httpSession  = null;
	public void init(FilterConfig filterConfig) throws ServletException {
		this._filterConfig = filterConfig;
	}
	
	public void destroy() {
		this._filterConfig = null;
	}
	
	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException,ServletException {
		if(request!=null){
			request.setCharacterEncoding("GBK");
		}
		if (_filterConfig == null) return;
		chain.doFilter(request, response);
	}
	private void setHeader() throws Exception {
		_httpRequest.setCharacterEncoding("GBK");
		//设置response的Header,使浏览器不使用本地缓存页面
		if (_httpRequest.getProtocol().compareTo("HTTP/1.0") == 0) {
			_httpResponse.setHeader("Pragma", "No-cache");
		} else if (_httpRequest.getProtocol().compareTo("HTTP/1.1") == 0) {
			_httpResponse.setHeader("Cache-Control", "no-cache");
		}
		_httpResponse.setDateHeader("Expires", 0);
	}
  
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?