Announcement Announcement Module
Collapse
No announcement yet.
Problem encode with @ResponseBody Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem encode with @ResponseBody

    I'm using Spring/Roo for a web app, and when i make some return with the @ResponseBody the Specifically, characters like " "... the response appear as "?". How can they be properly encoded ?
    am using spring 3.1.1. hope some one can help thx in advance.

  • #2
    Your response encoding does not match the encoding sent in the Response header.

    Comment


    • #3
      how can i set the response encoding?, but am not sure if that is the problem, because if y just print the string " " the result is
      ? ? ? ? , dont know if roo put a diferent encoding or in the pom.xml is missing something.

      Comment


      • #4
        Show us the controller method which writes the response.

        You can set the response header in several ways...
        In the html page via meta tag or via response.setHeader("Content-Type", ...) or response.setCharacterEncoding(..) and so on.

        Comment


        • #5
          this is the method

          @RequestMapping(value = "/maptest", method = RequestMethod.GET)
          public @ResponseBody
          String maptest() {
          System.out.println(" ");
          String respuesta=" ";
          return respuesta;
          }

          /// also i tried this in the method

          @RequestMapping(value = "/maptest", method = RequestMethod.GET)
          public ResponseEntity<String> maptest() {
          String respuesta=" ";
          HttpHeaders responseHeaders = new HttpHeaders();
          responseHeaders.add("Content-Type", "text/html;charset=UTF-8");
          return new ResponseEntity<String>(respuesta, responseHeaders, HttpStatus.CREATED);
          }

          with both the result was the same " ? ? ? " interrogation symbols

          Comment


          • #6
            Yon could try org.apache.commons.lang.StringEscapeUtils.escapeHt ml()

            @RequestMapping(value = "/maptest", method = RequestMethod.GET)
            public @ResponseBody String maptest() {
            System.out.println(" ");
            String respuesta=" ";
            return StringEscapeUtils.escapeHtml(respuesta);
            }

            Comment


            • #7
              Just look into the response in your browser and inspect the headers and meta-tags (F12 helps).

              Comment


              • #8
                the headers are set in UTF-8, that is no the problem, The server has no way of knowing how to interpret the special characters, even if i just print this System.out.println(" "); the console show ? ? ?, an i have the IDE set in UTF-8, the file set in UTF -8,but does not work, if i create a simple maven project the special characters work, but with spring - roo, with the example of the pizzashop, does not work the special characters, what is missing in the configuration?

                Comment

                Working...
                X