users@jersey.java.net

Re: [Jersey] Setting response encoding

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 14 Jun 2010 11:20:02 +0200

Hi Franz,

Perhaps Jetty is defaulting in the charset of the system? where as
Tomcat defaults to UTF-8?

Currently Jersey does not explicitly set the charset of the JSP as
declared on the produces media type. If i could do that i would, but i
do not know how, any ideas? is there a special attribute that can be
set on the request?

Paul.

On Jun 13, 2010, at 3:55 PM, Franz Wong wrote:

> FYI
>
> Instead of setting the encoding with <meta> only, I have set <%_at_page
> contentType="text/html; charset=utf-8" %> and now jetty works.
>
> Franz
>
> 2010/6/13 Franz Wong <franzwong_at_gmail.com>
> Thanks for your suggestion. However, that code cannot be compiled.
> And I changed to @Produces("text/html; charset=utf-8").
>
> Although the problem still exists, I just found that Tomcat works
> correctly while Jetty does not. I need to figure it out the reason
> then.
>
> Franz
>
>
> On Sun, Jun 13, 2010 at 8:05 PM, Suneel Marthi <suneel_marthi_at_yahoo.com
> > wrote:
> Try this:
>
> @Produces(MediaType.TEXT_HTML;MediaType.ACCEPT_CHARSET="UTF-8")
>
>
>
> From: Franz Wong <franzwong_at_gmail.com>
> To: users_at_jersey.dev.java.net
> Sent: Sun, June 13, 2010 4:20:44 AM
> Subject: [Jersey] Setting response encoding
>
> Hi,
>
> I am dealing with a multilingual problem. When I redirected to a jsp
> page, the non English characters cannot be shown correctly. e.g. "ÀR©]
> «ä" (Chinese characters) would become "???" However, there is no
> problem with English characters. How can I set the encoding to UTF-8?
>
> Here is the sample code.
>
> The service class
>
> @GET
> @Produces(MediaType.TEXT_HTML)
> public Viewable retrieve() {
> // some code here
> // response is a POJO
> response.setText("ÀR©]«ä"); // Non English characters here
> System.out.println(response.getText()); // The characters
> are correctly displayed in the console
> return new Viewable("/jsp/result.jsp", response);
> }
>
> The jsp
>
> <input type="text" readonly="true" value="${it.text}"/>
>
> I am using version 1.1.5.1.
>
> Thanks.
> Franz
>
>
>