⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 in3_cn.htm

📁 struts开发实例
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<style>
<!--
p
	{margin-right:0cm;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:宋体;
	}
span.name00
	{}
 p.MsoNormal
	{mso-style-parent:"";
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	font-size:10.5pt;
	font-family:"Times New Roman";
	margin-left:0cm; margin-right:0cm; margin-top:0cm}
-->
</style>
<!--[if !mso]>
<style>
v\:*         { behavior: url(#default#VML) }
o\:*         { behavior: url(#default#VML) }
.shape       { behavior: url(#default#VML) }
</style>
<![endif]-->
<link rel="File-List" href="in3_CN_files/filelist.xml">
<!--[if gte mso 9]>
<xml><o:shapedefaults v:ext="edit" spidmax="1027"/>
</xml><![endif]-->
</head>

<body>

<p style="text-indent: 44.15pt"><b>
<span lang="EN-US" style="font-size:22.0pt;font-family:黑体">Struts完全中文显示解决方案</span></b></p>
<p><span lang="EN-US" style="font-size:10.5pt">&nbsp; [背景知识]</span></p>
<p style="text-indent: 21.0pt">本背景知识参考了<span lang="EN-US" style="font-size: 10.5pt">IBM 
DeveloperWorks 中国网站提供的《<span class="name00">JSP/Servlet 中的汉字编码问题</span>》</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">1.问题的起源</span></p>
<p><span style="font-size:10.5pt">  每个国家(或区域)都规定了计算机信息交换用的字符编码集,如美国的<span lang="EN-US"> 
ASCII,中国的 GB2312-80,日本的 JIS 等,作为该国家/区域内信息处理的基础,有着统一编码的重要作用。字符编码集按长度分为 SBCS(单字节字符集),DBCS(双字节字符集)两大类。早期的软件(尤其是操作系统),为了解决本地字符信息的计算机处理,出现了各种本地化版本(L10N),为了区分,引进了 
LANG,Codepage 
等概念。但是由于各个本地字符集代码范围重叠,相互间信息交换困难;软件各个本地化版本独立维护成本较高。因此有必要将本地化工作中的共性抽取出来,作一致处理,将特别的本地化处理内容降低到最少。这也就是所谓的国际化(I18N)。各种语言信息被进一步规范为 
Locale 信息。处理的底层字符集变成了几乎包含了所有字形的 Unicode。</span></span></p>
<p><span style="font-size:10.5pt">  现在大部分具有国际化特征的软件核心字符处理都是以<span lang="EN-US"> 
Unicode 为基础的,在软件运行时根据当时的 Locale/Lang/Codepage 
设置确定相应的本地字符编码设置,并依此处理本地字符。在处理过程中需要实现 Unicode 和本地字符集的相互转换,甚或以 Unicode 
为中间的两个不同本地字符集的相互转换。这种方式在网络环境下被进一步延伸,任何网络两端的字符信息也需要根据字符集的设置转换成可接受的内容。</span></span></p>
<p><span style="font-size:10.5pt">  <span lang="EN-US">Java 语言内部是用 Unicode 
表示字符的,遵守 Unicode V2.0。Java 程序无论是从/往文件系统以字符流读/写文件,还是往 URL 连接写 HTML 信息,或从 URL 
连接读取参数值,都会有字符编码的转换。这样做虽然增加了编程的复杂度,容易引起混淆,但却是符合国际化的思想的。</span></span></p>
<p><span style="font-size:10.5pt">
  从理论上来说,这些根据字符集设置而进行的字符转换不应该产生太多问题。而事实是由于应用程序的实际运行环境不同,<span lang="EN-US">Unicode 
和各个本地字符集的补充、完善,以及系统或应用程序实现的不规范,转码时出现的问题时时困扰着程序员和用户。</span></span></p>
<p><span lang="EN-US" style="font-size:10.5pt">2.GB2312-80,GBK,GB18030-2000 
汉字字符集</span></p>
<p><span style="font-size:10.5pt">  其实解决<span lang="EN-US"> JAVA 
程序中的汉字编码问题的方法往往很简单,但理解其背后的原因,定位问题,还需要了解现有的汉字编码和编码转换。</span></span></p>
<p><span style="font-size:10.5pt">  <span lang="EN-US">GB2312-80 
是在国内计算机汉字信息技术发展初始阶段制定的,其中包含了大部分常用的一、二级汉字,和 9 
区的符号。该字符集是几乎所有的中文系统和国际化的软件都支持的中文字符集,这也是最基本的中文字符集。其编码范围是高位0xa1-0xfe,低位也是 
0xa1-0xfe;汉字从 0xb0a1 开始,结束于 0xf7fe;</span></span></p>
<p><span style="font-size:10.5pt">  <span lang="EN-US">GBK 是 GB2312-80 
的扩展,是向上兼容的。它包含了 20902 个汉字,其编码范围是 0x8140-0xfefe,剔除高位 0x80 的字位。其所有字符都可以一对一映射到 
Unicode 2.0,也就是说 JAVA 实际上提供了 GBK 字符集的支持。这是现阶段 Windows 
和其它一些中文操作系统的缺省字符集,但并不是所有的国际化软件都支持该字符集,感觉是他们并不完全知道 GBK 
是怎么回事。值得注意的是它不是国家标准,而只是规范。随着 GB18030-2000国标的发布,它将在不久的将来完成它的历史使命。</span></span></p>
<p><span style="font-size:10.5pt">  <span lang="EN-US">GB18030-2000(GBK2K) 在 GBK 
的基础上进一步扩展了汉字,增加了藏、蒙等少数民族的字形。GBK2K 从根本上解决了字位不够,字形不足的问题。它有几个特点:</span></span></p>
<p><span style="font-size:10.5pt">  ●它并没有确定所有的字形,只是规定了编码范围,留待以后扩充。</span></p>
<p><span style="font-size:10.5pt">  ●编码是变长的,其二字节部分与<span lang="EN-US"> GBK 
兼容;四字节部分是扩充的字形、字位,其编码范围是首字节 0x81-0xfe、二字节0x30-0x39、三字节 0x81-0xfe、四字节0x30-0x39。</span></span></p>
<p><span style="font-size:10.5pt">  ●它的推广是分阶段的,首先要求实现的是能够完全映射到<span lang="EN-US"> 
Unicode 3.0 标准的所有字形。</span></span></p>
<p><span style="font-size:10.5pt">  ●它是国家标准,是强制性的。</span></p>
<p><span style="font-size:10.5pt">  现在还没有任何一个操作系统或软件实现了<span lang="EN-US"> GBK2K 
的支持,这是现阶段和将来汉化的工作内容。</span></span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&nbsp;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">3.Struts程序设计中常见的 encoding 问题的</span></p>
<p style="text-indent:21.0pt"><span lang="EN-US" style="font-size:10.5pt">
(1)JSP页面中文显示问题;</span></p>
<p style="text-indent:21.0pt"><span lang="EN-US" style="font-size:10.5pt">
(2)中文资源显示问题</span></p>
<p style="text-indent:21.0pt"><span lang="EN-US" style="font-size:10.5pt">
(3)数据库数据中文显示</span></p>
<p style="text-indent:21.0pt"><span lang="EN-US" style="font-size:10.5pt">
(4)表单提交参数中的中文解决问题</span></p>
<p><span style="font-size:10.5pt">在<span lang="EN-US">JavaWebStudio中,提供完全的中文解决方案,上述所有问题都是自动解决的。</span></span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&nbsp;</span></p>
<p><span style="font-size:10.5pt">[实现方案]</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">1、JSP页面中文显示问题:</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">
&nbsp;&nbsp;&nbsp;在JavaWebStudio中,新建JSP文件时,自己加入如下代码:</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;%@ page 
contentType=&quot;text/html;charset=GB2312&quot; %&gt;</span></p>
<p><span style="font-size:10.5pt">这样<span lang="EN-US">JSP页面上的中文就可以正常显示了。</span></span></p>
<p><span style="font-size:10.5pt">
例如,在新建文件时,通过采单或用鼠标点击文件管理器栏右键,然后选择“新建文件”或“新建立专用文件”下图所示:</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&nbsp;<!--[if gte vml 1]><v:shapetype id="_x0000_t75"
 coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
 filled="f" stroked="f">
 <v:stroke joinstyle="miter"/>
 <v:formulas>
  <v:f eqn="if lineDrawn pixelLineWidth 0"/>
  <v:f eqn="sum @0 1 0"/>
  <v:f eqn="sum 0 0 @1"/>
  <v:f eqn="prod @2 1 2"/>
  <v:f eqn="prod @3 21600 pixelWidth"/>
  <v:f eqn="prod @3 21600 pixelHeight"/>
  <v:f eqn="sum @0 0 1"/>
  <v:f eqn="prod @6 1 2"/>
  <v:f eqn="prod @7 21600 pixelWidth"/>
  <v:f eqn="sum @8 21600 0"/>
  <v:f eqn="prod @7 21600 pixelHeight"/>
  <v:f eqn="sum @10 21600 0"/>
 </v:formulas>
 <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
 <o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="_x0000_s1025" type="#_x0000_t75" style='width:141pt;
 height:363pt'>
 <v:imagedata src="in3_CN_files/image001.png" o:title=""/>
</v:shape><![endif]--><![if !vml]><img border=0 width=188 height=484
src="in3_CN_files/image002.jpg" v:shapes="_x0000_s1025"><![endif]></span></p>
<p><span style="font-size:10.5pt">在新建文件对话框中选择要建立的文件类型,这里选择“<span lang="EN-US">JSP文件”,输入文件名:</span></span></p>
<p><span lang="EN-US" style="font-size:10.5pt"><!--[if gte vml 1]><v:shape
 id="_x0000_s1026" type="#_x0000_t75" style='width:343.5pt;height:318pt'>
 <v:imagedata src="in3_CN_files/image003.png" o:title=""/>
</v:shape><![endif]--><![if !vml]><img border=0 width=458 height=424
src="in3_CN_files/image004.jpg" v:shapes="_x0000_s1026"><![endif]></span></p>
<p><span style="font-size:10.5pt">生成的<span lang="EN-US">new.jsp文件内容如下:</span></span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;%@ page 
contentType=&quot;text/html;charset=GB2312&quot; %&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;html&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;head&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;title&gt;type1&lt;/title&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;/head&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;body&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;h1&gt;type1&lt;/h1&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;/body&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&lt;/html&gt;</span></p>
<p><span lang="EN-US" style="font-size:10.5pt">&nbsp;</span></p>
<p style="text-indent: 21.0pt"><span style="font-size:
10.5pt">其实,“新建文件”和“新建立专用文件”都是从模板里拷贝过来的。“新建文件”中建立的文件内容与<span lang="EN-US">\bin\模板\Jave 
Web 项目下的“空的普通JSP模板”中newfile目录的文件内容对应,“新建立专用文件”中建立的文件内容与\bin\模板\Jave Web 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -