JSP request.getParameter 乱码
发布网友
发布时间:2022-04-11 05:30
我来回答
共3个回答
热心网友
时间:2022-04-11 06:59
web.xml 增加编码过滤器
<filter>
<filter-name>encoding</filter-name>
<filter-class>
com.skysz.framework.filter.encoding.EncodingFilter
</filter-class>
</filter>
EnCodingFilter 实现类
public class EncodingFilter implements Filter {
private String encoding;
public void init(FilterConfig config) throws ServletException {
this.encoding = config.getInitParameter("encoding");
if (StringUtils.isNullOrBlank(this.encoding)) {
this.encoding = "UTF-8";
}
}
public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) srequest;
request.setCharacterEncoding(encoding);
chain.doFilter(srequest, sresponse);
}
public void destroy() {
}
}
热心网友
时间:2022-04-11 08:17
你是通过什么把值传过来的 action还是servlet
action的话在里面添加ServletActionContext.getResponse().setCharacterEncoding("UTF-8");
servlet的话获取HttpResponse对象执行setCharacterEncoding("UTF-8");追问
">
这个是代码,还是乱码?
追答同学 你按别人的答案走然后问我怎么回事 木有这么玩的
热心网友
时间:2022-04-11 09:52
response.setCharacterEncoding("UTF-8");
放在request.getParameter()前面