当前位置: 移动技术网 > IT编程>开发语言>Java > jsp中使用jstl导入html乱码问题解决方法

jsp中使用jstl导入html乱码问题解决方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

在jsp中通过jst的<c:import>导入html时会出现乱码的现象,其原因是org.apache.taglibs.standard.tag.common.core.importsupport

的charencoding的值为空则会出现charencoding为默认值也就是iso-8859-1

所幸的是charencoding可以直接通过<c:import>直接设置,所以只需设置一下就好了,许多人说可以通过在html中通过meta设置contenttype,但我试验过却不行,也是通过看jstl的源码才发现可以设置这个,因为平时都是用cimport导入jsp,jsp中设置是可行的,但是静态页中却不行。以下是importsupport的主要代码:

复制代码 代码如下:

 reader r = null;
      string charset;
      string charset;
      if ((this.charencoding != null) && (!this.charencoding.equals(""))) {
        charset = this.charencoding;
      }
      else {
        string contenttype = uc.getcontenttype();
        if (contenttype != null) {
          string charset = util.getcontenttypeattribute(contenttype, "charset");
          if (charset == null) charset = "iso-8859-1";
        }
        else {
          charset = "iso-8859-1";
        }
      }

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网