读书人

Page-encoding specified in XML prol

发布时间: 2013-11-08 17:51:56 作者: rapoo

Page-encoding specified in XML prolog (UTF-8) is different from

下面是JSP 2.0 Spec 中 contentType 和 pageEncoding 的述:
contentType
Defines the MIME type and the character encoding for the
response of the JSP page, and is also used in determining the
character encoding of the JSP page.
Values are either of the form “TYPE” or “TYPE;charset=
CHARSET”with an optional white space after the “;”.
“TYPE” is a MIME type, see the IANA registry at
http://www.iana.org/assignments/media-types/index.html
for useful values. “CHARSET”, if present, must be the IANA name for
a character encoding.
The default value for “TYPE” is “text/html” for JSP pages in
standard syntax, or “text/xml” for JSP documents in XML
syntax. If “CHARSET” is not specified, the response
character encoding is determined as described in
Section JSP.4.2, “Response Character Encoding”.
See Chapter JSP.4 for complete details on character
encodings.

pageEncoding

Describes the character encoding for the JSP page. The value
is of the form “CHARSET”, which must be the IANA name
for a character encoding. For JSP pages in standard syntax,
the character encoding for the JSP page is the charset given
by the pageEncoding attriute if it is present, otherwise the
charset given by the contentType attribute if it is present,
otherwise “ISO-8859-1”.
For JSP documents in XML syntax, the character encoding
for the JSP page is determined as described in section 4.3.3
and appendix F.1 of the XML specification. The pageEncoding
attribute is not needed for such documents. It is a
translation-time error if a document names different
encodings in its XML prolog / text declaration and in the
pageEncoding attribute. The corresponding JSP
configuration element is page-encoding (see
Section JSP.3.3.4, “Declaring Page Encodings”).
See Chapter JSP.4 for complete details on character
encodings.
For JSP pages in standard syntax, the page character encoding is determined
from the following sources:

A JSP configuration element page-encoding value whose URL pattern matches
the page.

The pageEncoding attribute of the page directive of the page. It is a translation-
time error to name different encodings in the pageEncoding attribute of
the page directive of a JSP page and in a JSP configuration element whose
URL pattern matches the page.

The charset value of the contentType attribute of the page directive. This is
used to determine the page character encoding if neither a JSP configuration
element page-encoding nor the pageEncoding attribute are provided.

If none of the above is provided, ISO-8859-1 is used as the default character
encoding.
於 contentType 和 pageEncoding 的差 和 中文JSP的定技巧:

contentType -- 指定的是JSP最 Browser(客端)所到的容的.
就是 Mozilla的 Character encoding, 或者是 IE6的 encoding. 例如 JSPtw Forum 用的contentType就是 Big5.

pageEncoding -- 指定JSP所用的
如果你的是 WIN98, 或 ME 的NOTEPAD事本JSP, 就一定是常用的是Big5 或 gb2312, 如果是用 WIN2k winXP的
NOTEPAD, SAVE就可以不同的,, 包括 ANSI(BIG5/GB2312)或 UTF-8 或 UNIONCODE(估是 UCS 16).

因 JSP要 次的"",
第一段用 pageEncoding, 第二段用 utf-8 至utf-8, 第三段就是由TOMCAT出的, 用的是contentType.

段一是 JSPC的 JSP至JAVA(.java)原的"翻", 它跟 pageEncoding 的定取JSP. 果是 由指定的
pageEncoding(utf-8,Big5,gb2312)的JSP 翻成一的utf-8 JAVA原(.java). 如果pageEncoding定了, 或定
( ISO8859-1), 出的 在段 就已是中文.

段二是由 JAVAC的JAVA原至JAVA BYTECODE的. 不JSP的是用(utf-8,Big5,gb2312),段一的果全
都是utf-8的ENCODING的JAVA原.
JAVAC用 utf-8的ENCODING取AVA原, 成字符串是 utf-8 ENCODING的二制(.class). 是 JAVA VIRTUAL MACNHINE
常字符串在 二制(JAVA BYTECODE)表的.

段三是TOMCAT(或其的application container)加和行段二得的JAVA二制, 出的果( 也就是BROWSER(客端))
到的. 一早藏在段一和二的contentType, 就了功效. ( 段一的 ).

response.setContentType("text/html; charset=utf-8");

出的可以是 utf-8, Big5, gb2312, 看的就是JSP ? contentType的定.

<%@ page session="false" pageEncoding="big5" contentType="text/html; charset=utf-8" %>

有, pageEncoding 和contentType的都是 ISO8859-1. 而便定了其中一, 另一就跟著一了(TOMCAT4.1.27是如此).
但不是, 看的各自JSPC的理方式. 而pageEncoding不等於contentType, 更有利洲的文字 CJKV系JSP的和展示,
(例pageEncoding=Big5 不等於 contentType=utf-8).

一的解方法是在包含和被包含文件的始部分都加上:

<%@ page contentType="text/html;charset=GB2312" language="java" %>

下面是一示例:main.jsp

<%@ page contentType="text/html;charset=GB2312" language="java" %>
<html>
<head><title></title></head>
<body>
<%@ include file="hello.jsp" %>
<b><p align="center"><font color="#ff0000">主中的表:</font></p></b>
<br>
<table width="98%" height="20" border="0" cellpadding="0" align="center" bgcolor="#99CCCC" cellspacing="0">
<tr>
<td align="center" valign="middle"><font color="wihte">
转自:http://yk1987.blog.hexun.com.tw/64083290_d.html?

?

读书人网 >XML SOAP

热点推荐