当前位置: 代码迷 >> 综合 >> web.xm里过滤器过滤之后,String类型的数据还是乱码解决方案
  详细解决方案

web.xm里过滤器过滤之后,String类型的数据还是乱码解决方案

热度:38   发布时间:2024-01-18 03:31:20.0

如果web.xm里字符编码l过滤器过滤之后,该String类型的数据还是乱码,应该通过一下方式进行转换

new String(字符串.getBytes("ISO8859-1"),"UTF-8")

或者在set、get方法的时候设置编码,可以有效解决乱码问题

private String fileName;//下载时的文件名称
public String getFileName() throws UnsupportedEncodingException{return new String(fileName.getBytes(), "ISO8859-1");}
public void setFileName(String fileName) throws UnsupportedEncodingException {this.fileName = new String(fileName.getBytes("ISO-8859-1"), "utf-8");}






  相关解决方案