struts2 get方式传中文乱码
解决方法1:若使用tomcat, 打开server.xml, 找到如下, 加下URIEncoding="UTF-8", 大概在50行左右这种方法比较简单, 但是依赖于web容器, 不知道化成其他容器后会不会还有类似的设置?<Connector port="8080" protocol="HTTP/1.1"connectionTimeou
·
解决方法1:
若使用tomcat, 打开server.xml, 找到如下, 加下URIEncoding="UTF-8", 大概在50行左右
这种方法比较简单, 但是依赖于web容器, 不知道化成其他容器后会不会还有类似的设置?
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
解决方法2:
通过指定编码构造一个新的字符串, 但这种方法用于post会出现问题,问题在于getBytes中的字符编码
post默认不是用“ISO-8859-1”的所以以下方法是用在post传值中是不可取的
condition = new String(condition.getBytes("ISO-8859-1"), "utf-8");
解决方法3:(网上的思路是这样的, 但我试了下不行?)
添加filter, 对参数进行处理
public class CharFilter implements Filter{
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)