resp.setCharacterEncoding("UTF8") weirdness

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

resp.setCharacterEncoding("UTF8") weirdness

jian chen
Hi,

I came across a weird issue with the encoding. I had this in my servlet:
resp.setCharacterEncoding("UTF8"); and I was testing my web app. in
Internet Explorer.

In my web app. javascript, I have a call like:
document.getElementById('xxx").innerHTML=req.responseText;
where req is a XmlHttpRequest javascript object (AJAX web app.)

My IE browser gave a system error on this javascript line.

However, if I used
OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
My IE browser renders fine.

I maybe wrong but this seems to me that somewhere in Jetty , the
encoding routine resulted from resp.setCharacterEncoding(...) is not
correct.

For now, I switched to use
OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
instead of
resp.setCharacterEncoding("UTF8")

Could there be a problem with Jetty output stream based on a encoding?

Thanks,

Jian


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: resp.setCharacterEncoding("UTF8") weirdness

Kent Johnson
jian chen wrote:

> Hi,
>
> I came across a weird issue with the encoding. I had this in my servlet:
> resp.setCharacterEncoding("UTF8"); and I was testing my web app. in
> Internet Explorer.
>
> In my web app. javascript, I have a call like:
> document.getElementById('xxx").innerHTML=req.responseText;
> where req is a XmlHttpRequest javascript object (AJAX web app.)
>
> My IE browser gave a system error on this javascript line.
>
> However, if I used
> OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
> My IE browser renders fine.

When you use setCharacterEncoding() do you call resp.getWriter() to get the stream? Don't write
directly to resp.getOutputStream().

Kent



-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: resp.setCharacterEncoding("UTF8") weirdness

jian chen
No, I did not use the outputstream. I had
resp.setCharacterEncoding("UTF8");
Writer out = resp.getWriter();
out.println(...);

So, I think it should be a problem with Jetty's implmentation of response.

Maybe internally Jetty did not use
new OutputStreamWriter(resp.getOutputStream(), "UTF8");
to wrap around an outputstream with UTF-8 encoding?

Cheers,

Jian


On 5/29/05, Kent Johnson <[hidden email]> wrote:

> jian chen wrote:
> > Hi,
> >
> > I came across a weird issue with the encoding. I had this in my servlet:
> > resp.setCharacterEncoding("UTF8"); and I was testing my web app. in
> > Internet Explorer.
> >
> > In my web app. javascript, I have a call like:
> > document.getElementById('xxx").innerHTML=req.responseText;
> > where req is a XmlHttpRequest javascript object (AJAX web app.)
> >
> > My IE browser gave a system error on this javascript line.
> >
> > However, if I used
> > OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
> > My IE browser renders fine.
>
> When you use setCharacterEncoding() do you call resp.getWriter() to get the stream? Don't write
> directly to resp.getOutputStream().
>
> Kent
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by Yahoo.
> Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
> Search APIs Find out how you can build Yahoo! directly into your own
> Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
> _______________________________________________
> jetty-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-discuss
>


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: resp.setCharacterEncoding("UTF8") weirdness

Greg Wilkins-5
In reply to this post by jian chen
Jian,

When you use the outputstreamWriter, do you also set the content-type of the response?
Actually, do you set the content-type at all?

Can you use a network sniffer tool (or even firefox) so we can see the difference in
the HTTP headers of the response.

cheers


jian chen wrote:

> Hi,
>
> I came across a weird issue with the encoding. I had this in my servlet:
> resp.setCharacterEncoding("UTF8"); and I was testing my web app. in
> Internet Explorer.
>
> In my web app. javascript, I have a call like:
> document.getElementById('xxx").innerHTML=req.responseText;
> where req is a XmlHttpRequest javascript object (AJAX web app.)
>
> My IE browser gave a system error on this javascript line.
>
> However, if I used
> OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
> My IE browser renders fine.
>
> I maybe wrong but this seems to me that somewhere in Jetty , the
> encoding routine resulted from resp.setCharacterEncoding(...) is not
> correct.
>
> For now, I switched to use
> OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
> instead of
> resp.setCharacterEncoding("UTF8")
>
> Could there be a problem with Jetty output stream based on a encoding?
>
> Thanks,
>
> Jian
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by Yahoo.
> Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
> Search APIs Find out how you can build Yahoo! directly into your own
> Applications - visit http://developer.yahoo.net/?fr=fad-ysdn-ostg-q22005



-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: resp.setCharacterEncoding("UTF8") weirdness

jian chen
Hi, Greg,

Thanks for your attention for this issue. I do set the content type as follows:
resp.setContentType("text/html; charset=UTF-8");

Now before I was trying to use a sniffer to debug it further, I found
an even better fix for it.

You know what was the problem? I used UTF8 in the following:
resp.setCharacterEncoding("UTF8");
Writer out = resp.getWriter();
ve.mergeTemplate(actualTmpl, ctx, out);
out.flush();
where ve is a Velocity template engine instance.

When I changed UTF8 to UTF-8 like the following:
resp.setCharacterEncoding("UTF-8");
Writer out = resp.getWriter();
ve.mergeTemplate(actualTmpl, ctx, out);
out.flush();
it works!

Please note that it also works for the following snippet:
OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
ve.mergeTemplate(actualTmpl, ctx, out);
out.flush();

So, I guess if I use Jetty's resp.setCharacterEncoding(...), I have to
use "UTF-8". I also tried to change the content type from UTF-8 to
UTF8 by
resp.setContentType("text/html; charset=UTF8"); but it did not work
unless I set resp.setCharacterEncoding("UTF-8");

Let me know if you want me to provide some more info. I can use
Ethereal to get more debug info.

Cheers,

Jian

On 5/30/05, Greg Wilkins <[hidden email]> wrote:

> Jian,
>
> When you use the outputstreamWriter, do you also set the content-type of the response?
> Actually, do you set the content-type at all?
>
> Can you use a network sniffer tool (or even firefox) so we can see the difference in
> the HTTP headers of the response.
>
> cheers
>
>
> jian chen wrote:
> > Hi,
> >
> > I came across a weird issue with the encoding. I had this in my servlet:
> > resp.setCharacterEncoding("UTF8"); and I was testing my web app. in
> > Internet Explorer.
> >
> > In my web app. javascript, I have a call like:
> > document.getElementById('xxx").innerHTML=req.responseText;
> > where req is a XmlHttpRequest javascript object (AJAX web app.)
> >
> > My IE browser gave a system error on this javascript line.
> >
> > However, if I used
> > OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
> > My IE browser renders fine.
> >
> > I maybe wrong but this seems to me that somewhere in Jetty , the
> > encoding routine resulted from resp.setCharacterEncoding(...) is not
> > correct.
> >
> > For now, I switched to use
> > OutputStreamWriter out = new OutputStreamWriter(resp.getOutputStream(), "UTF8");
> > instead of
> > resp.setCharacterEncoding("UTF8")
> >
> > Could there be a problem with Jetty output stream based on a encoding?
> >
> > Thanks,
> >
> > Jian
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by Yahoo.
> > Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
> > Search APIs Find out how you can build Yahoo! directly into your own
> > Applications - visit http://developer.yahoo.net/?fr=fad-ysdn-ostg-q22005
>
>


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss