struts2+hibernate表单提交数据中文乱码,人快疯了,求解
代码:
public class CharacterEncodingFilter extends HttpServlet implements Filter {
/**
* 专门写的转码用(UTF-8),防止中文乱码
*/
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");//
chain.doFilter(request, response);//这两句,改为一下的,类继承HttpServlet
HttpServletRequest request1 = (HttpServletRequest)request;
request1.setCharacterEncoding("UTF-8");
HttpServletResponse response1 = (HttpServletResponse)response;
response1.setContentType("text/html;charset=utf-8");
chain.doFilter(request1, response1);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
}