jsp中使用jstl導入html亂碼問題解決方法
在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的源碼才發(fā)現可以設置這個,因為平時都是用cimport導入jsp,jsp中設置是可行的,但是靜態(tài)頁中卻不行。以下是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";
}
}
相關文章
解決request.getParameter取值后的if判斷為NULL的問題
這篇文章主要介紹了解決request.getParameter取值后的if判斷為NULL的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03JBuilder2005單元測試之創(chuàng)建測試固件
這篇文章主要介紹了JBuilder2005單元測試之創(chuàng)建測試固件2006-10-10