0

We're migrating from JBOSS 4.x to 5.1, and having problems with the character encodings.

Certain characters in the extended ASCII range were O.K. under the previous JBoss version, but with the new JBoss they cause problems (e.g., incomplete http responses).

The solution seems to be to use UTF-8, but the only way I've found to cause JBoss to send charset=UTF-8 in the Content-Type header is to specify this in the page directive of every JSP page. Otherwise the charset in the http response is specified as ISO-8859-1. I'd like to find a global solution to set the charset to UTF-8.

I've seen several other questions about character encoding with JBoss, but none seem to address the encoding of http responses.

I have tried without success:

  • in jboss/bin/run.bat, setting set "JAVA_OPTS=-Dfile.encoding=utf-8 %JAVA_OPTS%"
  • in jboss/server//deploy/jbossweb.sar/server.xml setting
Mike Kantor
  • 1,400
  • 4
  • 24
  • 45

1 Answers1

1

I have used spring encoding filter to set the encoding:

<filter>
 <filter-name>encodingFilter</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>  
 <init-param>  
    <param-name>forceEncoding</param-name>  
    <param-value>true</param-value>  
 </init-param>  
</filter>  
<filter-mapping>  
 <filter-name>encodingFilter</filter-name>  
 <url-pattern>/*</url-pattern>  
</filter-mapping> 

If you dont use spring, you will need a servlet filter that sets the encoding.

randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72
  • It's hard to believe there's no configuration to do this. But the filter approach worked. – Mike Kantor Oct 09 '12 at 20:11
  • 1
    Note that the filter sets the encoding for http response. You will also need to set the file.encoding since this property is used for the default encoding in Java, all readers and writers would default to using this encoding. This property comes into picture when processing your form parameters. – randominstanceOfLivingThing Oct 10 '12 at 14:43
  • Good point. I know about the two places mentioned in bullet points in the original question. Are there other places where the encoding needs to be specified? – Mike Kantor Oct 10 '12 at 19:54