Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

servlet encoding problem

843842Jun 12 2009 — edited Jun 18 2009
Hi,

I have a servlet which need to send xml(Which can have any unicode characters) as response.

Below are my trails.
*1>>>*
PrintWriter out = response.getWriter();
response.setContentType("text/xml;charset=ISO-8859-1");
out.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
out.write("<xml>ÀàÁáÂâÃãÄäÅÅ</xml>");

This works perfect.I mean the browser is showing all the characters properly.

*2>>>*

The same code when setting is utf-8 as below the browser is giving below error.

Code :

PrintWriter out = response.getWriter();
response.setContentType("text/xml;charset=UTF-8");
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
out.write("<xml>ÀàÁáÂâÃãÄäÅÅ</xml>");

Error on browser :

An invalid character was found in text content. Error processing resource 'http://myurl...

When is saw the view source.. all the characters looks pretty good. but the browser is giving the above error


*3>>>*

code:

PrintWriter out = response.getWriter();
response.setContentType("text/xml;charset=ISO-8859-1");
out.write("<xml>ÀàÁáÂâÃãÄäÅÅ</xml>");

This code is with out the xml specification.This output is displayed as plain text instead as xml.

Is there some thing else i am missing, i want to use utf-8 encoding inorder to support all languages.But i am restricted to iso-8859-1 where i can display only latin lanaguages .

I am using oracle application server.

Any help would be great....

Thanks,
Satya
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 16 2009
Added on Jun 12 2009
16 comments
760 views