前端传数据到servlet数据乱码
使用过滤器
过滤器代码
package demo; 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; import javax.servlet.annotation.WebFilter; import javax.servlet.annotation.WebInitParam; /** * Servlet Filter implementation class CharsetEncodingFilter */ @WebFilter(urlPatterns = {"/*"}, initParams = { @WebInitParam(name = "encoding", value = "UTF-8")}) public class CharsetEncodingFilter implements Filter { private FilterConfig config; public CharsetEncodingFilter() { } @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding(config.getInitParameter("encoding")); chain.doFilter(request, response); } @Override public void init(FilterConfig fConfig) throws ServletException { this.config = fConfig; } }
相关推荐
JudeJoo 2020-08-21
meleto 2020-08-15
lantingyue 2020-07-30
zyjj 2020-07-27
pengpengflyjhp 2020-07-19
htofly 2020-07-09
三动 2020-06-21
hyxinyu 2020-06-08
洗尽铅华 2020-06-07
shayuchaor 2020-06-07
xiamubawei 2020-06-04
方志朋 2020-05-30
一片荷叶 2020-05-27
spring艳 2020-05-16
zhangdy0 2020-05-06
80304053 2020-05-04
neweastsun 2020-05-04
shuiluobu 2020-05-01
itjavashuai 2020-04-26