java传参乱码,总结

阅读更多
1.整体思想,编码方式统一(采用utf-8)
2页面显示中文乱码

<%page pageEncoding="utf-8"%>

3传递中文参数乱码

修改server.xml(解决get方式)


    redirectPort="8443" URIEncoding="UTF-8"/>



编写过滤器(Filter)(解决post方式)

package servlets; 

import java.io.IOException;

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 {
    public void init(FilterConfig config) throws ServletException {
    }

    public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        chain.doFilter(request, response);
    }

    public void destroy() {
    }
}


在web.xml注册


            EncodingFilter
            servlets.EncodingFilter
       

       
            EncodingFilter
            *.do
       

你可能感兴趣的:(中文乱码)