`
Alrale
  • 浏览: 61862 次
  • 来自: fantasy
社区版块
存档分类
最新评论

"Page Encoding","contentType"的区别

    博客分类:
  • Java
阅读更多

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:

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

 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

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

分享到:
评论

相关推荐

    jsp Unsupported encoding- gb2312 错误原因.docx

    jsp Unsupported encoding- gb2312 错误原因 JSP Unsupported encoding:gb2312 错误是指在 JSP 页面中使用了 gb2312 编码,但是 Tomcat 服务器却不能识别该编码,导致 JasperException 异常的错误。 造成该错误的...

    JAVA过滤器filter request.setCharacterEncoding仅对POST提交起作用,对GET提交还是会出现乱码问题

    5. **JSP页面设置**:在JSP页面顶部添加`&lt;%@ page contentType="text/html;charset=UTF-8" %&gt;`,确保页面的输出是按照UTF-8编码的。 6. **HTTP头设置**:服务器可以在响应头中设置`Content-Type`字段,包含`charset...

    jsp Unsupported encoding: gb2312 错误原因

    综上所述,`jsp Unsupported encoding: gb2312` 错误是由于JSP页面的`contentType`设置不正确导致的,修复的关键在于删除字符集名称前的空格。在开发过程中,遵循编码规范,使用通用的字符集,以及确保所有环境的...

    中文乱码解决

    对于JSP,可以在文件头部添加`&lt;%@ page contentType="text/html;charset=GBK"%&gt;`或`&lt;%@ page contentType="text/html;charset=gb2312"%&gt;`来指定页面的字符编码。 2. **数据交互编码问题**: - 当Java程序与其他...

    jsp连接MySQL实现插入insert操作功能示例

    下午终于实现了jsp连接MySQL执行插入操作的功能。...@ page contentType=”text/html;charset=utf-8″%&gt; &lt;&#37; request.setCharacterEncoding(“UTF-8”); response.setCharacterEncoding(“UTF-8”); respo

    jsp登陆界面源代码

    &lt;%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%&gt;&lt;%@ page import="java.util.*" %&gt;&lt;!DOCTYPE ...

    解决Tomcat中文乱码

    &lt;%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%&gt; ``` 4. **数据库连接设置**: - 在数据库连接字符串中加入字符集参数,确保数据库连接时使用正确的字符集。 ```java...

    中文乱码问题分析 自己总结的

    对于 JSP,在文件头加上 `&lt;%@page contentType="text/html;charset=GBK"%&gt;` 或 `&lt;%@page contentType="text/html;charset=gb2312"%&gt;`基本上就能解决这类乱码问题。 在 Java 程序与存储媒介交互时,字符(char)与字节...

    2种解决JSP中request乱码问题.docx

    %@page contentType="text/html; charset=UTF-8"% 这个指令告诉浏览器使用 UTF-8 编码来解析页面内容,从而避免乱码问题。 第二种方法:使用 Filter 在 web.xml 文件中添加以下代码: &lt;filter-name&gt;Set ...

    JSP在Servlet中的几个编码的作用及原理 .txt

    具体涉及到了`pageEncoding`, `contentType`, `request.setCharacterEncoding`, `response.setCharacterEncoding`等几个关键概念。 --- ### 正文 在JSP与Servlet的实际开发过程中,中文乱码问题是非常常见的一个...

    jsp中影响编码的属性及其设置小结

    其中`response.setContentType()`和`response.setHeader()`具有最高优先级,其次是`response.setCharacterEncoding()`,最后是`&lt;%@page contentType="text/html...`的设置。 总之,正确设置JSP的编码属性是确保网页...

    解决JSP中文乱码问题

    &lt;%@ page contentType="text/html;charset=GBK"%&gt; ``` 或者 ```jsp &lt;%@ page contentType="text/html;charset=UTF-8"%&gt; ``` 这样可以告诉浏览器以指定的字符集来解析页面内容。 接下来,我们来看看两种常见的JSP...

    JSP中文乱码的产生原因及解决方案.docx

    为了避免这种情况,可以在Java源代码中尽量避免使用中文(注释除外),如果必须使用,可以通过命令行参数如`-encoding GBK`、`-encoding gb2312`或`-encoding UTF-8`进行指定编码编译。对于JSP,可以在文件顶部添加`...

    jsp中charset和pageEncoding

    2. **使用 `&lt;jsp:include&gt;` 替代 `&lt;%@ include %&gt;`**:使用 `&lt;jsp:include page="date.jsp" flush="true"/&gt;` 可以避免 `contentType` 的重复设置问题,因为 `&lt;jsp:include&gt;` 会忽略被包含页面中的 `contentType` ...

    5种JSP页面显示为乱码的解决方法

    &lt;page-encoding&gt;GBK&lt;/page-encoding&gt; *.html&lt;/url-pattern&gt; &lt;page-encoding&gt;GBK&lt;/page-encoding&gt; ``` #### 2. 设置Servlet请求的编码 当用户通过表单提交数据时,如果请求参数的编码与服务器默认编码不...

    中文乱码问题处理方法.docx

    解决办法是添加Page指令,例如:&lt;%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%&gt; 2. URL传递参数中文乱码 当我们将中文字符作为参数传递给另一个页面时,可能会出现乱码...

    如何处理JSP中文乱码问题,IBM portal 中文乱码.docx

    对于JSP文件,可以在文件头部添加指令来设定页面编码,如`&lt;%@ page contentType="text/html;charset=UTF-8" %&gt;`,这将指示JSP页面使用UTF-8编码。 当遇到JSP页面乱码时,通常是因为页面编码设置不正确。有两种常见...

    Tomcat中文乱码解决方法参考.pdf

    可以通过 contentType、pageEncoding 或 response.setCharacterEncoding 设置网页编码。例如,可以在 JSP 文件中添加以下代码: ```jsp &lt;%@ page contentType="text/html;charset=gbk" %&gt; ``` 或 ```jsp &lt;%@ page...

    校内网络_用户管理模块 管理员设置向导

    校园网数据库,sql数据库的应用,有存储过程,数据库语言的应用,&lt;%@page contentType="text/html; charset=gb2312" language="java" errorPage="error.jsp"%&gt; &lt;%@page import="com.suninformation.*,...

Global site tag (gtag.js) - Google Analytics