Tomcat 提交时的编码问题
一般 Tomcat 默认编码都不是UTF8 所以只有先手动设置 server.xml (Connector加个属性URIEncoding=”utf-8″)
或者加入如下过滤器,才能得到提交文本的正确编码
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 EncodingFilter implements Filter { private String charset=“UTF-8”; public void destroy() { // TODO Auto-generated method stub } @SuppressWarnings("unchecked") public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub request.setCharacterEncoding(charset); chain.doFilter(request, response); } public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub if(arg0.getInitParameter("charset")!=null)charset=arg0.getInitParameter("charset"); } }