这篇文章主要介绍了J2EE中文乱码怎么解决的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇J2EE中文乱码怎么解决文章都会有所收获,下面我们一起来看看吧。
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.http.HttpServletRequest;
public class EncodingFilter implements Filter {
private String targetEncoding = "ASCII"; // 初始值是ASCII编码
public void destroy() {
}
public void init(FilterConfig config) throws ServletException {
this.targetEncoding = config.getInitParameter("Encoding");
}
public void doFilter(ServletRequest srequest, ServletResponse sresponse,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) srequest;
request.setCharacterEncoding(targetEncoding);
chain.doFilter(srequest, sresponse);
}
}
<!-- 配置 -->
关于“J2EE中文乱码怎么解决”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“J2EE中文乱码怎么解决”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网行业资讯频道。