8

I’m using Java 6, JBoss 7.1.3 and Spring 3.2.11.RELEASE. Despite the fact that we set this in our application context

<bean id="systemPrereqs"
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" value="#{@systemProperties}" />
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <!-- The new Properties -->
        <util:properties>
            <prop key="org.apache.catalina.connector.URI_ENCODING">UTF-8</prop>
        </util:properties>
    </property>
</bean>

I notice on my JSPs, special characters aren’t rendered correctly unless we specify a

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

at the top of the JSP page. This is fine for one JSP, but is cumbersome to have to go through the entire application adding these directives. Is there a more global place I can specify this, like in a Spring context or somewhere, that will universally add the above directive to all our JSP pages?

Dave
  • 15,639
  • 133
  • 442
  • 830

4 Answers4

0

Add the following System property also:

<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
0

Put in your web.xml the following:

<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>

More info: https://docs.oracle.com/cd/E17904_01/web.1111/e13712/web_xml.htm#WBAPP539

code_angel
  • 1,537
  • 1
  • 11
  • 21
0

Put the following in your web.xml .

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>
Birhan Nega
  • 663
  • 12
  • 24
  • Hi, How is your answer different from code_angel's, entered on 1/6? – Dave Jan 10 '17 at 17:11
  • I added an optional line `default-content-type` to make it different again ;) – code_angel Jan 10 '17 at 17:32
  • K, let me give it a go with that directive because the original answer as you ahd it didn't work for me. SPecifically cnotent stored in the db as 'and “Evidence” ' (notice the smart quotes, hope those cut and pasted over) was still being rendered as ' and ?Evidence? ' – Dave Jan 11 '17 at 21:02
0

How about using filter?

<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
</init-param>
</filter>

<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Boldbayar
  • 862
  • 1
  • 9
  • 22