问题在于custname,也就是你发送请求的数据编码和接收的不一致。看看你请求页面的编码是什么,gbk或者utf-8,如何后台
request.setCharacterEncoding("UTF-8")或者request.setCharacterEncoding("GBK").
在response.getWriter()之前加上这两行代码试试:
response.setCharacterEncoding("utf-8"); response.setContentType("text/html; charset=utf-8");
还是有乱码。
在获取请求参数值之前加上:
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
或者写一个拦截器,在web.xml配置上就好了
public class EncodingFilter implements Filter { @Override public void init(FilterConfig arg0) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); filterChain.doFilter(request, response); } @Override public void destroy() { }