JBoss AS 7.1 and UTF-8 encoding

Today I faced an interesting problem at work. It was JSP + Spring MVC 4 + Apache Tiles 2 + JBoss AS 7.1 application. JSP pages contain UTF-8 encoded Russian text encoding and should be displayed in UTF-8 in browser. I placed  @Page directive in some pages:

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

Pages with above directive started to display non-English text perfectly fine. Others continued to show me unreadable rubbish instead (in default JBoss ISO-8859-1). So I already had a solution:

Solution 1 – modify every JSP page in the project to add proper @page directive.

But my idea was to not configure every page separately.  I opened JBoss standalone.xml and put the following fragment at the end of the file before the </server> closing tag:

 
    <system-properties>
        <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
        <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
    </system-properties>
 

.. and caught JBoss startup error  JBAS014789: Unexpected element '{urn:jboss:domain:1.2}system-properties' encountered

After some surfing I found an interesting resolution: on some versions of JBoss <system-properties> should be placed below <extensions>  section. I put it there and got my UTF-8 working. My final standalone.xml looks like that:

Solution 2. Put <system-properties> section just below <extensions> in standalone.xml:

<extensions>
        <extension module="org.jboss.as.clustering.infinispan"/>
        <extension module="org.jboss.as.configadmin"/>
        <extension module="org.jboss.as.connector"/>
        <extension module="org.jboss.as.deployment-scanner"/>
        <extension module="org.jboss.as.ee"/>
        <extension module="org.jboss.as.ejb3"/>
        <extension module="org.jboss.as.jaxrs"/>
        <extension module="org.jboss.as.jdr"/>
        <extension module="org.jboss.as.jmx"/>
        <extension module="org.jboss.as.jpa"/>
        <extension module="org.jboss.as.logging"/>
        <extension module="org.jboss.as.mail"/>
        <extension module="org.jboss.as.naming"/>
        <extension module="org.jboss.as.osgi"/>
        <extension module="org.jboss.as.pojo"/>
        <extension module="org.jboss.as.remoting"/>
        <extension module="org.jboss.as.sar"/>
        <extension module="org.jboss.as.security"/>
        <extension module="org.jboss.as.threads"/>
        <extension module="org.jboss.as.transactions"/>
        <extension module="org.jboss.as.web"/>
        <extension module="org.jboss.as.webservices"/>
        <extension module="org.jboss.as.weld"/>
    </extensions>
 
    <system-properties>
        <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
        <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
    </system-properties>

Leave a Reply

Your email address will not be published.