Set the default encoding to UTF-8 for all JSPs wit

2019-08-29 02:39发布

问题:

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>