乱码问题 有兴趣的看看 估计大部分都不知道为什么

cfd406635982 cfd406635982 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

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 {
protected String encoding = null;

protected FilterConfig filterConfig = null;

public void destroy() {
this.encoding = null;
this.filterConfig = null;
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String encoding = selectEncoding(request);
// request.getParameter("");放到这儿也是乱码
if (encoding != null) {
request.setCharacterEncoding(encoding);
}
request.getParameter("");// 如果没有的话,则jsp页面提交到后台bean会是乱码
chain.doFilter(request, response);
}

public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
}

protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}


虽然现在不乱码了 但是不知道原因是什么
前台的编码一致。
系统是win7
只要request.getParameter("");把这句删了就会中文乱码
留着就没事 从来没有遇到过。
web.xml配置放到最前面了
希望高手能不能给出原因
...全文

相关推荐

评论 10
收藏 已收藏
分享
返回顶部
cfd406635982
Web 开发 81,108 成员 341,721 内容