- 浏览: 62355 次
- 来自: fantasy
最新评论
-
dygf1987:
还有别的原因吗?我的这三个都起来了
ORA-12560:协议适配器错误(oracle10g) -
wyt1213:
按说人种之间不应该存在这种心态的差别,那么,谁的过错造就大众这 ...
我又犯嫉妒了,借用此文鞭策下自己 -
Alrale:
网易安徽宿州网友 ip:6 ...
不内涵,聚光灯在评论处,你们懂得 -
Alrale:
dunhuacc12 写道Alrale 写道dunhuacc1 ...
人的性格真的不可以改变吗? -
dunhuacc12:
Alrale 写道dunhuacc12 写道突然间觉得超女也没 ...
人的性格真的不可以改变吗?
Web components usually use PrintWriter to produce responses; PrintWriter automatically encodes using ISO-8859-1. Servlets can also output binary data using OutputStream classes, which perform no encoding. An application that uses a character set that cannot use the default encoding must explicitly set a different encoding.
For web components, three encodings must be considered:
-
Request
-
Page (JSP pages)
-
Response
Request Encoding
The request encoding is the character encoding in which parameters in an incoming request are interpreted. Currently, many browsers do not send a request encoding qualifier with the Content-Type header. In such cases, a web container will use the default encoding, ISO-8859-1, to parse request data.
If the client hasn’t set character encoding and the request data is encoded with a different encoding from the default, the data won’t be interpreted correctly. To remedy this situation, you can use the
ServletRequest.setCharacterEncoding(String enc)
method to override the character encoding supplied by the container.
To control the request encoding from JSP pages, you can use the JSTL
fmt:requestEncoding
tag.
You must call the method or tag before parsing any request parameters or reading any input from the request. Calling the method or tag once data has been read will not affect the encoding.
Page Encoding
For JSP pages, the page encoding is the character encoding in which the file is encoded.
For JSP pages in standard syntax, the page encoding is determined from the following sources:
-
The page encoding value of a JSP property group (see Setting Properties for Groups of JSP Pages) 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 property group.
-
The CHARSET value of the contentType attribute of the page directive.
If none of these is provided, ISO-8859-1 is used as the default page encoding.
The pageEncoding and contentType attributes determine the page character encoding of only the file that physically contains the page directive. A web container raises a translation-time error if an unsupported page encoding is specified.
Response Encoding
The response encoding is the character encoding of the textual response generated by a web component. The response encoding must be set appropriately so that the characters are rendered correctly for a given locale. A web container sets an initial response encoding for a JSP page from the following sources:
-
The CHARSET value of the contentType attribute of the page directive
-
The encoding specified by the pageEncoding attribute of the page directive
-
The page encoding value of a JSP property group whose URL pattern matches the page
If none of these is provided, ISO-8859-1 is used as the default response encoding.
The setCharacterEncoding, setContentType, and setLocale methods can be called repeatedly to change the character encoding. Calls made after the servlet response’s getWriter method has been called or after the response is committed have no effect on the character encoding. Data is sent to the response stream on buffer flushes (for buffered pages) or on encountering the first content on unbuffered pages.
Calls to setContentType set the character encoding only if the given content type string provides a value for the charset attribute. Calls to setLocale set the character encoding only if neither setCharacterEncoding nor setContentType has set the character encoding before. To control the response encoding from JSP pages, you can use the JSTL fmt.setLocale tag.
To obtain the character encoding for a locale, the setLocale method checks the locale encoding mapping for the web application. For example, to map Japanese to the Japanese-specific encoding Shift_JIS, follow these steps:
-
Select the WAR.
-
Click the Advanced Settings button.
-
In the Locale Character Encoding table, Click the Add button.
-
Enter ja in the Extension column.
-
Enter Shift_JIS in the Character Encoding column.
If a mapping is not set for the web application, setLocale uses a Application Server mapping.
The first application in Chapter 5, JavaServer Pages Technology allows a user to choose an English string representation of a locale from all the locales available to the Java 2 platform and then outputs a date localized for that locale. To ensure that the characters in the date can be rendered correctly for a wide variety of character sets, the JSP page that generates the date sets the response encoding to UTF-8 by using the following directive:
<%@ page contentType="text/html; charset=UTF-8" %>
发表评论
-
【转载】cpu 硬件同步原语(compare and swap)
2012-03-13 08:38 1959cpu 硬件同步原语(compare and swap) 支 ... -
转载 web.xml元素:常见设定值一览
2010-08-05 19:40 811本文对web.xml元素中的常 ... -
SCJP拾遗(一) 默认构造函数的访问权限
2010-06-02 14:10 2976Java 类 (1)如果没有指定构造函数,编译时会自动创建一 ... -
Html元素<textarea>内回车的处理
2010-04-08 09:08 2645做事从小事入手,从细节入手. Html元素<te ... -
对给定的数字(float)四舍五入到小数点后两位
2010-02-03 13:29 1283float f = 123.456f; float f1 ... -
"Page Encoding","contentType"的区别
2009-09-14 10:16 1476SUN官方解释(见《The Java EE 5 Tutoria ... -
Jdbc demo
2008-10-24 16:02 1232String url = "jdbc:mysql:/ ... -
Java Exception 继承关系图
2008-10-16 17:43 2912[img]/upload/attachment/42963/5 ... -
Log4j 总结(六) log4j 之 WriterAppender
2008-10-16 10:33 1780public class WriterAppender ext ... -
Log4j 总结(五) log4j 之 配置文件
2008-10-16 10:21 1134前面几个都是概念,现在是实战 Log4j支持两种格式的配置文件 ... -
Log4j 总结(四) log4j 之 Appenders and Layouts
2008-10-16 09:49 886Logger Name Added Appenders ... -
Log4j 总结(三) log4j 之 Logger
2008-10-16 09:36 1078Loggers are named entities. Log ... -
Log4j 总结(一) log4j特色
2008-10-16 08:47 1111One of the distinctive features ... -
Log4j 总结(二) log4j主要的三个组件
2008-10-07 14:12 929Log4j has three main components ... -
检测指定URL是否有效连接的JAVA代码
2008-09-09 17:26 4656try{ URL url = new URL(url_s); ... -
Jsp的执行过程
2008-09-09 16:03 2280JSP 的执行过程 (1) 客户端发出Request (请求) ... -
Servlet 2.4 对比 2.3 的改变
2008-09-09 15:56 26882003年11月底,J2EE 1.4规范正式发布,Servle ... -
Tomcat 各版本支持的Servlet规范
2008-09-09 15:43 1442Servlet/JSP Spec Apache ... -
Servlet 的生命周期 (摘自JSP2.0技术手册)
2008-09-09 15:25 966(1) 产生 Servlet,加载到Servlet Engin ...
相关推荐
在IT行业中,字符集编码是基础且至关重要的概念,尤其对于Java开发者来说,理解编码机制是处理各种文本数据的关键。本文将围绕“Java字符集编码简记”这一主题,深入探讨相关知识点,并结合标签“源码”和“工具”,...
1. **设置IDEA全局编码**:进入IDEA的设置(Preferences),找到Editor -> File Encodings,将全局编码、项目编码和默认文本编码都设置为GBK。 2. **针对单个文件设置编码**:对于特定的GBK文件,可以在文件的右下...
所以问题的关键在于,eclipse的控制台默认使用GBK编码,而JAVA源代码中的中文字符是以UTF-8编码存储的。 为了解决这个问题,我们可以采取以下几种策略: 1. **修改Eclipse配置**:在Eclipse中,可以设置工作空间的...
在Java编程中,正确识别和处理文件的编码是至关重要的,因为不同的文件可能采用不同的字符编码,例如ASCII、UTF-8、GBK等。本篇将深入探讨如何在Java中自动获取文件的编码,并介绍一个编码检测的工具类——...
开发平台编码模式设置 在Eclipse中,可以进入`Window > Preferences > General > Workspace`,设置`Text file encoding`为`UTF-8`;对于IntelliJ IDEA,可以在`File > Settings > Editor > File Encodings`中将...
Learn about the morass of the data that accompanies each Unicode character, and how Unicode deals with normalization, the bidirectional algorithm, and the handling of East Asian characters. ...
1. 字符和字符串处理:文档中提到了字符编码(Character Encodings)、字符类(CharacterClass)、CharSequence接口、String类、StringBuilder类、CharBuffer类、Charset类等。这些内容是Java进行文本处理的基石。...
### 字符编码(Encodings) 字符编码是计算机科学中的一个关键概念,它定义了字符与数字之间的映射关系,使得文本可以在计算机系统中存储和传输。书中讲解了多种字符编码标准,包括ASCII、ISO-8859、Windows-1252和...
这可以通过在gconf-editor中找到`/apps/gedit-2/preferences/encodings/default_save`路径并设置相应的编码值来实现。 - 当使用gedit打开文件时,如果仍然遇到乱码问题,可以尝试手动选择文件的编码格式。在gedit的...
其中,encoding 指的是 Vim 内部使用的字符编码方式,fileencoding 指的是当前编辑的文件的字符编码方式,fileencodings 是 Vim 自动探测 fileencoding 的顺序列表,termencoding 指的是终端的字符编码方式。...
Java的I/O库非常强大,包括了流(Streams)、缓冲区(Buffer)、字符编码(Encodings)和对象序列化(Serialization)等多个方面。在这个实验中,可能使用了`java.io`和`java.nio`包下的类,如`InputStream`、`OutputStream`...
Ubuntu操作系统中处理中文编码问题是一个常见的用户需求,尤其在与Windows系统交互数据时。由于两个系统默认使用的编码格式不同,通常情况下Windows中文版默认使用GBK编码,而Ubuntu在支持中文之后,默认使用的是UTF...
- `in_charset`: 输入字符串的编码。 - `out_charset`: 输出字符串期望的编码。 - `str`: 需要转换的字符串。 以下示例展示了如何将UTF-8编码的字符串转换为GBK编码: ```php if ($encode == "UTF-8") { $...
### LaTeX2ε源代码概述与关键技术点解析 #### 标题:LaTeX2ε源代码 #### 描述:LaTeX2ε源代码介绍 #### 标签:LaTeX2ε源代码 #### 部分内容摘要分析: ##### 1. 引言 LaTeX2ε(通常写作LaTeX2e)是LaTeX...
来自有关已知HTML字符编码标签的信息。 安装 该软件包仅适用于ESM:需要使用Node 12+才能使用它,并且必须将其import而不是require d。 : npm install html-encodings 用 import { list , groups } from '...
7. InputStreamReader is a Java class used to convert a byte stream (InputStream) into a character stream (Reader), facilitating the reading of text data in different character encodings. 8. In Java, ...
encodings.xml