Setting response encoding

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting response encoding

Franz Wong
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. "靜夜思" (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("靜夜思"); // 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
Reply | Threaded
Open this post in threaded view
|

Re: Setting response encoding

smarthi
Try this:

@Produces(MediaType.TEXT_HTML;MediaType.ACCEPT_CHARSET="UTF-8")




From: Franz Wong <[hidden email]>
To: [hidden email]
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. "靜夜思" (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("靜夜思"); // 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

Reply | Threaded
Open this post in threaded view
|

Re: Setting response encoding

Franz Wong
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 <[hidden email]> wrote:
Try this:

@Produces(MediaType.TEXT_HTML;MediaType.ACCEPT_CHARSET="UTF-8")




From: Franz Wong <[hidden email]>
To: [hidden email]
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. "靜夜思" (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("靜夜思"); // 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


Reply | Threaded
Open this post in threaded view
|

Re: Setting response encoding

Franz Wong
FYI

Instead of setting the encoding with <meta> only, I have set <%@page contentType="text/html; charset=utf-8" %> and now jetty works.

Franz

2010/6/13 Franz Wong <[hidden email]>
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 <[hidden email]> wrote:
Try this:

@Produces(MediaType.TEXT_HTML;MediaType.ACCEPT_CHARSET="UTF-8")




From: Franz Wong <[hidden email]>
To: [hidden email]
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. "靜夜思" (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("靜夜思"); // 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



Reply | Threaded
Open this post in threaded view
|

Re: Setting response encoding

Paul Sandoz
Administrator
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 <%@page contentType="text/html; charset=utf-8" %> and now jetty works.

Franz

2010/6/13 Franz Wong <[hidden email]>
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 <[hidden email]> wrote:
Try this:

@Produces(MediaType.TEXT_HTML;MediaType.ACCEPT_CHARSET="UTF-8")




From: Franz Wong <[hidden email]>
To: [hidden email]
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. "靜夜思" (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("靜夜思"); // 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