Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:42:06+00:00 2026-06-08T09:42:06+00:00

I’ve got problem with character encoding of my http responses. I read many tips,

  • 0

I’ve got problem with character encoding of my http responses. I read many tips, tutorials etc., but I can’t resolve my problem. We are using Spring MVC with Hibernate and ExtJS as view technology. All data are returns as JSON using @ResponseBody on controllers method. Example method:

@RequestMapping(method = RequestMethod.POST, value = "dispatcher")
@ResponseBody
public String dispatcherPost(HttpServletRequest req, HttpServletResponse resp, HttpSession session) {
    return process(req, resp, session);
}

There is simple dispatching mechanism for dispatching url commands (not really important in this case). Process method is doing something with parameters and return JSON. This JSON contains for example data from database (PostgreSQL 9.1.4). Data in Postgres are stored in UTF-8 and are ‘visible correctly’ for example in pgAdmin. We can also see valid data (from database) while debuging in eclipse. It all looks like there is everything ok with getting data from the Postgres. Problem starts when we want to return them via @ResponseBody annotated method. Method ‘process’ returns valid string (I can see in debugging mode) with utf-8 characters but in web browser (chrome, firefox) there are ‘?’ instead of polish characters which are stored in database. Looking into firebug I can see that response headers are partially valid: ‘Content-type: text/html;charset=UTF-8’. I told ‘partially’, because I have this line of code in process method:

`resp.setContentType(“application/json;charset=UTF-8”);`

where resp is HttpServletResponse. I’ve tried adding springs bean post processor from this solution: http://stackoverflow.com/questions/3616359/who-sets-response-content-type-in-spring-mvc-responsebody/3617594#3617594 but it doesn’t works. I’ve got also character encoding filter in web.xml

<!-- Force Char 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>

So basically the problem is with returning well encoded JSON from server. Any idea?

EDIT:

I paste code into proccess method:

System.err.println(“TEST ” + System.getProperty(“file.encoding”));
System.err.println(“TEST normal: ” + response);
System.err.println(“TEST cp1250: ” + new String(response.getBytes(),”cp1250″));
System.err.println(“TEST UTF-8: ” + new String(response.getBytes(),”UTF-8″));

And result is something like this:

TEST Cp1250
TEST normal: {“users”:[{“login”:”userąęśćółżń”}]}
TEST cp1250: {“users”:[{“login”:”userąęśćółżń”}]}
TEST UTF-8: {“users”:[{“login”:”user?????”}]}

Thanks, Arek

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:42:09+00:00Added an answer on June 8, 2026 at 9:42 am

    Ok, it seems to be something weird with http://static.springsource.org/spring/docs/3.0.x/reference/remoting.html#rest-message-conversion and @ResponseBody annotation which is using springs http message converters. I don’t have time for go into creating custom message converters, so solution for me is remove @ResponseBody annotation and use something like this:

    @RequestMapping(method = RequestMethod.GET, value = "dispatcher")
    public void dispatcherGet(HttpServletRequest req, HttpServletResponse resp, HttpSession session) {
        String response =  process(req, resp, session);
        try {
            resp.getWriter().write(response);
            resp.getWriter().flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    Maybe this will helps someone. Thanks, Arek

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.