Set the default encoding to UTF-8 for all JSPs without using @page directives

谁说我不能喝 提交于 2019-12-25 03:06:06

问题


What I would like to avoid is specifying a page directive at the beginning of every JSP.

As I understand, without the following line, the default for the Content-Type for the page will be set to "text/html;charset=ISO-8859-1".

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

Is there a configuration option that does the same thing without having to explicitly set the charset for every single JSP file in an application?


回答1:


You can add the following to 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>


来源:https://stackoverflow.com/questions/22407500/set-the-default-encoding-to-utf-8-for-all-jsps-without-using-page-directives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!