This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,323 Users
  • 2,269,776 Discussions


JSP charset problem with ISO-8859-7 (Greek) using post via XMLHttpRequest

843840 Member Posts: 49,995 Green Ribbon
Hello everybody.

I am developing web applications in Greek. I have an MVC model. A JSP page (jsp1) posts a form using XMLHttpRequest object to a servlet. The javascript code iterates through the elements of the for and makes a string like:


but in Greek names and characters. This sting is put to the body of the XMLHttpRequest and then gets posted to a servlet.

Then the servlet takes it and does some database inserts and updates and then the request from the XMLHttpRequest object, is forwarded as it is to another jsp page (ssp2) to show the results on the screen.
Finally the html that is produced from jsp2 is returned to the XMLHttpRequest object and put to a div element on jsp1 using div1.innerHTML = [jsp2 html contents].

The problem is that The Greek characters on jsp2 that came from jsp1 are shown like ??????.

both jsp1 and jsp2 pages have a directive
<%@ page language="java" contentType="text/html pageEncoding="ISO-8859-7"%>

Withput pageEncoding="ISO-8859-7" the hardcoded Greek labels cannot be shown.

I have tried request.setCharacterEncoding("ISO-8859-7"); on all three (jsp1, servlet and jsp2) but it doesn't work.

Any ideas? I am really stuck here.

Thanx in advance


  • mrityunjoy
    mrityunjoy Member Posts: 346
    edited Jun 18, 2010 3:28PM
    Couple of things :
    a. You must consider setting request encoding, page encoding and response encoding.
    b. Whether database setup is done to store and retrieve Greek characters. You can test it separately. And it is surely not the culprit for not displaying data in JSP page received from another JSP.
    c. Server setup is done to support ISO-8859-7 character set. For example, in tomcat conf/server.xml the <connector > should have attribute URIEncoding set to appropriate character set. For example:
    <Connector port="8080"
                   maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups="false" redirectPort="8443" acceptCount="100"
                   debug="0" connectionTimeout="20000" 
    d. In case application code manipulates (byte to string or string to byte conversion) Greek string data, it must consider appropriate character set whenever necessary.

    I suggest one more thing: Without XMLHttpRequest test your JSP pages normally to verify your application works with Greek data.

  • 843840
    843840 Member Posts: 49,995 Green Ribbon
    Thank you for your answer.

    Well the number (a) of your answer i have tested strongly.
    In (b) i agree it is irelevant, i just mentioned it
    (d) is perhaps out of the question. It is a very simple process of transferring data. Whatever string comes, goes to the jsp2.

    I have already tested it without XMLHttpRequest by <input type="submit"... and it works fine. That is why i mentioned all the proccess that i used on XMLHttprequest.

    But another thing has come to surface. I tested it with firefox and it works fine bot with XMLHttpRequest and submit button. Only Internet explorer has this problem with XMLHttpRequest. I think i must search the cause on the character encoding manipulation of explorer and how it reacts with div.innerHTML.

    If there are any suggestions, i am all ears....
  • mrityunjoy
    mrityunjoy Member Posts: 346
    Try setting request header in XMLHttpRequest in Javascript:
    var client = new XMLHttpRequest();"POST", "/log");
    client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
  • 843840
    843840 Member Posts: 49,995 Green Ribbon
    It worked!

    Actually since there i a body with PARAM_NAME=PARAM_VALUE on the XMLHttpRequest there must be

    this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

    If i write
    this.xmlHttp.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
    the params will not be transfered and be null when i receive them in java code.

    I have tried exactly the same with ISO-8879-7 but not with UTF-8. It works fine with this simple example that i have discussed before as well
    as with more complex MVC that i have already developed and just waiting for the correction.
    I have tried it with Internet Explorer as well as Firefox.

    Thank you for your answer. You really helped me with this mess. When i get the time i must study a little about character encodings....
  • mrityunjoy
    mrityunjoy Member Posts: 346
    Thanassis.Diamantis wrote:
    It worked!
    Thank you for your answer. You really helped me with this mess. When i get the time i must study a little about character encodings....
    You are welcome.

  • 879158
    879158 Member Posts: 1

    Could you give some more details about how you fixed that?

    I have the same problem when i am trying to print greek in a jsp through a servlet and its driving me crazy...

    Thanks in advance
This discussion has been closed.