這篇文章主要介紹了J2EE中文亂碼怎么解決的相關(guān)知識,內(nèi)容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇J2EE中文亂碼怎么解決文章都會有所收獲,下面我們一起來看看吧。
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供涇川網(wǎng)站建設(shè)、涇川做網(wǎng)站、涇川網(wǎng)站設(shè)計、涇川網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、涇川企業(yè)網(wǎng)站模板建站服務(wù),十多年涇川做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
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.http.HttpServletRequest;
/**
* 過濾器
*
* @author Administrator
*
*/
public class EncodingFilter implements Filter {
private String targetEncoding = "ASCII"; // 初始值是ASCII編碼
public void destroy() {
}
public void init(FilterConfig config) throws ServletException {
this.targetEncoding = config.getInitParameter("Encoding");
}
public void doFilter(ServletRequest srequest, ServletResponse sresponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) srequest;
request.setCharacterEncoding(targetEncoding);
chain.doFilter(srequest, sresponse);
}
}