【转载+整理】关于JSP页面中的pageEncoding和contentType两种属性的区别

本文详细解析了JSP页面中pageEncoding与contentType属性的区别及其作用过程。pageEncoding负责JSP文件本身的编码,而contentType则定义了服务器发送给客户端的内容编码。两者对于正确处理亚洲语言字符集尤其重要。

关于JSP页面中的pageEncoding和contentType两种属性的区别:

  pageEncoding是jsp文件本身的编码

  contentType的charset是指服务器发送给客户端时的内容编码

 

  JSP要经过两次的“编码”,第一阶段会用pageEncoding,第二阶段会用utf-8至utf-8,第三阶段就是由Tomcat出来的网页, 用的是contentType。

  第一阶段是jsp编译成.java,它会根据pageEncoding的设定读取jsp,结果是由指定的编码方案翻译成统一的UTF-8 JAVA源码(即.java),如果pageEncoding设定错了,或没有设定,出来的就是中文乱码。

  第二阶段是由JAVAC的JAVA源码至java byteCode的编译,不论JSP编写时候用的是什么编码方案,经过这个阶段的结果全部是UTF-8的encoding的java源码。

  JAVAC用UTF-8的encoding读取java源码,编译成UTF-8 encoding的二进制码(即.class),这是JVM对常数字串在二进制码(java encoding)内表达的规范。

  第三阶段是Tomcat(或其的application container)载入和执行阶段二的来的JAVA二进制码,输出的结果,也就是在客户端见到的,这时隐藏在阶段一和阶段二的参数contentType就发挥了功效

 

  contentType的設定.

  pageEncoding 和contentType的预设都是 ISO8859-1. 而随便设定了其中一个, 另一个就跟着一样了(TOMCAT4.1.27是如此). 但这不是绝对的, 这要看各自JSPC的处理方式. 而pageEncoding不等于contentType, 更有利亚洲区的文字 CJKV系JSP网页的开发和展示, (例pageEncoding=GB2312 不等于 contentType=utf-8)。

  jsp文件不像.java,.java在被编译器读入的时候默认采用的是操作系统所设定的locale所对应的编码,比如中国大陆就是GBK,台湾就是BIG5或者MS950。而一般我们不管是在记事本还是在ue中写代码,如果没有经过特别转码的话,写出来的都是本地编码格式的内容。所以编译器采用的方法刚好可以让虚拟机得到正确的资料。

  但是jsp文件不是这样,它没有这个默认转码过程,但是指定了pageEncoding就可以实现正确转码了。

  举个例子:

 

 

<%@ page contentType="text/html; charset=UTF-8" %>

 

  大都会打印出乱码,因为输入的“你好”是gbk的,但是服务器是否正确抓到“你好”不得而知。

  但是如果更改为

 

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="GBK" %>

  这样就服务器一定会是正确抓到“你好”了。

 

 

-----------------------------------------------------修整的 分割线----------------------------------------------------------

 

 

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:

 

Java代码 复制代码
  1. <%@ page contentType="text/html; charset=UTF-8" %>  
<%@ 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:

 

Java代码 复制代码
  1. <%@ page pageEncoding="UTF-8" %>  
<%@ 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:

    1. Expand the JSP Property Group node.

    2. 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文档有

 

Html代码 复制代码
  1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

来标识客户端编码,即指定访问服务器的浏览器是用什么编码.

<%@ page contentType="text/html; charset=UTF-8" %>
内容概要:本文档围绕六自由度机械臂的ANN人工神经网络设计展开,涵盖正向与逆向运动学求解、正向动力学控制,并采用拉格朗日-欧拉法推导逆向动力学方程,所有内容均通过Matlab代码实现。同时结合RRT路径规划与B样条优化技术,提升机械臂运动轨迹的合理性与平滑性。文中还涉及多种先进算法与仿真技术的应用,如状态估计中的UKF、AUKF、EKF等滤波方法,以及PINN、INN、CNN-LSTM等神经网络模型在工程问题中的建模与求解,展示了Matlab在机器人控制、智能算法与系统仿真中的强大能力。; 适合人群:具备一定Ma六自由度机械臂ANN人工神经网络设计:正向逆向运动学求解、正向动力学控制、拉格朗日-欧拉法推导逆向动力学方程(Matlab代码实现)tlab编程基础,从事机器人控制、自动化、智能制造、人工智能等相关领域的科研人员及研究生;熟悉运动学、动力学建模或对神经网络在控制系统中应用感兴趣的工程技术人员。; 使用场景及目标:①实现六自由度机械臂的精确运动学与动力学建模;②利用人工神经网络解决传统解析方法难以处理的非线性控制问题;③结合路径规划与轨迹优化提升机械臂作业效率;④掌握基于Matlab的状态估计、数据融合与智能算法仿真方法; 阅读建议:建议结合提供的Matlab代码进行实践操作,重点理解运动学建模与神经网络控制的设计流程,关注算法实现细节与仿真结果分析,同时参考文中提及的多种优化与估计方法拓展研究思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值