文章目錄
jsp前台傳值到後台亂碼問題解決方案:
後台中設定一個filter,過濾轉換一下編碼,就可以了!
具體操作如下:
1、filter類:
public class LoggerFilter implements Filter {
private String encoding="GBK";
private FilterConfig fiterConfig=null;
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
this.encoding =fiterConfig.getInitParameter("encoding");
if(this.encoding==null){
encoding="GBK";
}
request.setCharacterEncoding(this.encoding);
response.setCharacterEncoding(this.encoding);
filterChain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
}
2、web.xml檔案:
<filter>
<filter-name>loggerfilter</filter-name>
<filter-class>cn.com.sinosoft.filter.LoggerFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>loggerfilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>