欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-11-21 19:11:28
在jsp中通过jst的导入html时会出现乱码的现象,其原因是org.apache.taglibs.standard.tag.common....

在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";
        }
      }