這段時間經常看到有人問到web開發中怎麼中文總是?號
方法一
<%@ page language=
或者<%@ page contenttype=
這個方法用於jsp頁面中的中文顯示
方法二
過濾器使用主要針對表單提交
編寫一個SetCharacterEncodingFilter類
import java
import javax
import javax
import javax
import javax
import javax
import javax
public class SetCharacterEncodingFilter implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void init(FilterConfig filterConfig) throws ServletException {
this
this
String value=filterConfig
if(value==null)
this
else if(value
this
else
this
}
public void doFilter(ServletRequest request
// TODO 自動生成方法存根
if (ignore || (request
String encoding = selectEncoding(request);
if (encoding != null)
request
}
chain
}
public void destroy() {
// TODO 自動生成方法存根
this
this
}
protected String selectEncoding(ServletRequest request) {
return (this
}
}
[
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20723.html