SUN官方解释(见《The Java EE 5 Tutorial 》)
Response and Page Encoding
You also use the contentType attribute to specify the encoding of the response. For example, the date application specifies that the page should be encoded using UTF-8, an encoding that supports almost all locales, using the following page directive:
<%@ page contentType="text/html; charset=UTF-8" %>
If the response encoding weren’t set, the localized dates would not be rendered correctly.
To set the source encoding of the page itself, you would use the following page directive:
<%@ page pageEncoding="UTF-8" %>
You can also set the page encoding of a set of JSP pages. The value of the page encoding varies depending on the configuration specified in the JSP configuration section of the web application deployment descriptor (see Declaring Page Encodings).
Declaring Page Encodings
You set the page encoding of a group of JSP pages using the JSP property group configuration in the deployment descriptor by doing one of the following:
-
If you are using the Pages section of the web.xml editor pane in NetBeans IDE:
-
Expand the JSP Property Group node.
-
Enter the page encoding in the Page Encoding field.
-
-
If you are editing the web.xml file by hand, add a page-encoding element to the jsp-property-group element in the deployment descriptor and set it to one of the valid character encoding codes, which are the same as those accepted by the pageEncoding attribute of the page directive.
A translation-time error results if you define the page encoding of a JSP page with one value in the JSP configuration element and then give it a different value in a pageEncoding directive.
一般HTML文档有
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
来标识客户端编码,即指定访问服务器的浏览器是用什么编码.
本文介绍了如何使用JSP页面指令设置响应内容类型及字符集,包括response和page encoding的配置方法,并说明了这些设置对于国际化内容正确显示的重要性。此外,还讲解了如何通过部署描述符统一设置一组JSP页面的编码。
1203

被折叠的 条评论
为什么被折叠?



