有两个页面,console.jsp和menu.htm,代码如下:
...
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
...
<c:import url="menu.htm"/>
...
其中,console.jsp设置charset为"UTF-8",并使用<c:import>标签引入了menu.htm(menu.htm使用UTF-8编辑).
直接打开menu.htm,然后将页面的Encoding设置为Unicode(UTF-8),字符可以正确显示.
但打开console.jsp时,import进来的内容却出现乱码现象.
为<c:import>设置charEncoding="UTF-8"后,问题才得以解决.
...
<c:import url="menu.htm" charEncoding="UTF-8"/>'
...
可为什么console.jsp中已经设置了charset,引入menu.xml时还会出现乱码呢?
查看JSTL的源码后得到了答案(我查看的是jakarta-taglibs-standard-1.1.2-src.zip中的代码).
在org.apache.taglibs.standard.tag.common.core.ImportSupport(<c:import>的实现类)中发现如下代码:
public static final String DEFAULT_ENCODING = "ISO-8859-1";
...
// handle absolute URLs ourselves, using java.net.URL
URL u = new URL(target);
URLConnection uc = u.openConnection();
InputStream i = uc.getInputStream();
// okay, we've got a stream; encode it appropriately
Reader r = null;
String charSet;
if (charEncoding != null && !charEncoding.equals("")) {
charSet = charEncoding;
}
else {
// charSet extracted according to RFC 2045, section 5.1
String contentType = uc.getContentType();
if (contentType != null) {
charSet = Util.getContentTypeAttribute(contentType, "charset");
if (charSet == null) charSet = DEFAULT_ENCODING;
}
else {
charSet = DEFAULT_ENCODING;
}
}
从上面的代码可以看出,如果不设置charEncoding,标签将会查看目标页的编码(menu.htm中没有设置content-type,所以得到的contentType为null),charSet 最终被设置为DEFAULT_ENCODING,即"ISO-8859-1".导致乱码的出现.
PS:
可以建立一个Filter,并加入下面的代码:
...
response.setCharacterEncoding("UTF-8");
...
也可以在menu.htm中加入
上面两种都可以避免乱码的出现(...应该是吧)
附件是jakarta-taglibs-standard-1.1.2-src.zip~
分享到:
相关推荐
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字...
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字...
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字格式化...
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字格式化...
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字格式化...
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字...
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字...
13.3.9、<c:import>标签 13.3.10、<c:url>标签 13.3.11、<c:redirect>标签 13.4、国际化标签库 13.4.1、<fmt:setLocale>标签 13.4.2、<fmt:requestEncoding>标签 13.4.3、读取资源文件 13.4.4、数字格式化...
<#import "/libs/mylib.ftl" as my> <@my.copyright date="1999-2002"/> <#-- "my"在freemarker里被称作namespace --> <#import "/libs/mylib.ftl" as my> <@my.copyright date="1999-2002"/> <#...
其它的运行符可以作用于数字和日期,但不能作用于字符串,大部分的时候,使用gt等字母运算符代替>会有更好的效果,因为 FreeMarker会把>解释成FTL标签的结束字符,当然,也可以使用括号来避免这种情况,如:<#if (x>y)> ...
53 <taglib-location>/WEB-INF/tld/c.tld</taglib-location> 54 </taglib> 55 <taglib> 56 <taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri> 57 <taglib-location>/WEB-INF/tld/fmt.tld</taglib-location...
<a href="javascript:function()">word</a> 上一网页源 asp: request.servervariables("HTTP_REFERER") javascript: document.referrer 释放内存 CollectGarbage(); 禁止右键 document.oncontextmenu = ...
LabelEncoder可以将标签分配一个0—n_classes-1之间的编码 将各种标签分配一个可数的连续编号: >>> from sklearn import preprocessing >>> le = preprocessing.LabelEncoder() >>> le.fit([1, 2, 2, 6]) ...
sb.append("<title>欢迎使用新安人才网个人专区</title>").append("\n"); Elements meta = doc.getElementsByTag("meta"); sb.append(meta.toString()).append("\n"); ///////////////////////////...
对于标签分类:最后生成的可以是类别标签索引,也可以是one-hot向量(独热编码) 我们举一个五分类的例子: 可以用[3]:表示第三种分类 也可以用one-hot向量[0,0,1,0,0]:表示第三种分类 那么我们接下来用pytorch和...
在文件上载和表单提交的过程中,有两个指的关心的问题,一是上载的数据是是采用的那种方式的编码,这个问题的可以从 Content-Type 中得到答案,另一个是问题是上载的数据量有多少即 Content-Length ,知道了它,就...
动态INCLUDE用jsp:include动作实现 <jsp:include page="included.jsp" flush="true" />它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数。 静态INCLUDE用include伪码实现,定不会检查所含文件的...
动态INCLUDE用jsp:include动作实现 <jsp:include page="included.jsp" flush="true" />它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数。 静态INCLUDE用include伪码实现,定不会检查所含文件...
在所有标签页中,双击数据源属性值并输入电子数据表的位置,例如“C:\Excel2007\Import\SampleData.xlsx”作为导入数据的数据源的Microsoft Office Excel 2007文件名称和路径。然后双击扩展属性并选择Excel 12.0作为...
14.6.2 使用@import导入 14.7 创建样式类 14.7.1 用类设定简单表格样式 14.7.2 使用特定类选择器 14.8 ID选择器和ID属性 14.9 使用〈span〉标签重写或添加样式 14.9.1 〈span〉...