1.整体思想,编码方式统一(采用utf-8)
2页面显示中文乱码
<%page pageEncoding="utf-8"%>
3传递中文参数乱码
修改server.xml(解决get方式)
<Connector port="8080" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000"
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注册
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>servlets.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
java GET POST提交乱码问题
原创
©著作权归作者所有:来自51CTO博客作者wx6392bc05d177b的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章