码迷,mamicode.com
首页 > 数据库 > 详细

页面转码器(从mysql输到页面代码乱码)

时间:2014-09-24 20:24:27      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:des   style   io   java   ar   sp   on   c   代码   

package com.test.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;

public class EncodeFilter implements Filter {  

private String encode;      

public EncodeFilter() {     }

 public void destroy() {  }

 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{   response.setCharacterEncoding(encode);   

  chain.doFilter(request, response);  }

 public void init(FilterConfig fConfig) throws ServletException {   

encode = fConfig.getInitParameter("encode");  }

}

 

 

web.xml

 

 

<filter>
    <display-name>EncodeFilter</display-name>
    <filter-name>EncodeFilter</filter-name>
    <filter-class>com.test.filter.EncodeFilter</filter-class>
    <init-param>
      <param-name>encode</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>EncodeFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

页面转码器(从mysql输到页面代码乱码)

标签:des   style   io   java   ar   sp   on   c   代码   

原文地址:http://www.cnblogs.com/liyong0125/p/3991239.html

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