码迷,mamicode.com
首页 > 其他好文 > 详细

CharacterEncodingFilter -处理字符格式

时间:2015-05-16 13:15:27      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

package com.pb.news.web.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

/**
* Servlet Filter implementation class CharacterEncodingFilter
*/
@WebFilter("/*")
public class CharacterEncodingFilter implements Filter {

/**
* Default constructor.
*/
public CharacterEncodingFilter() {
// TODO Auto-generated constructor stub
}

/**
* @see Filter#destroy()
*/
public void destroy() {
// TODO Auto-generated method stub
}

/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
// pass the request along the filter chain
//调用请求时的编码格式
request.setCharacterEncoding("UTF-8");
//调用web资源,也可以调用其他过滤器
chain.doFilter(request, response);
//设置响应时的编码格式
response.setCharacterEncoding("UTF-8");
}

/**
* @see Filter#init(FilterConfig)
*/
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}

}

CharacterEncodingFilter -处理字符格式

标签:

原文地址:http://www.cnblogs.com/JesseCary/p/4507617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!