在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";
}
}
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!