【问题标题】:Set the default encoding to UTF-8 for all JSPs without using @page directives将所有 JSP 的默认编码设置为 UTF-8,而不使用 @page 指令
【发布时间】:2014-04-19 21:24:18
【问题描述】:

我想避免在每个 JSP 的开头指定一个页面指令。

据我了解,如果没有以下行,页面的 Content-Type 的默认值将设置为“text/html;charset=ISO-8859-1”。

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

是否有无需为应用程序中的每个 JSP 文件显式设置字符集即可执行相同操作的配置选项?

【问题讨论】:

    标签: jsp utf-8 character-encoding


    【解决方案1】:

    您可以在 web.xml 中添加以下内容

    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <page-encoding>UTF-8</page-encoding>
            <default-content-type>text/html</default-content-type>
        </jsp-property-group>
    </jsp-config>
    

    【讨论】:

    • 在与服务器打了一阵子之后,看来这可能已经成功了。
    • 警告:我在 AppEngine 项目中完成了这项工作,一旦升级到 Java8,JSP 就会停止工作。
    猜你喜欢
    • 2012-03-10
    • 2012-02-01
    • 2014-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 2014-02-09
    相关资源
    最近更新 更多