Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Problem to displaying hindi fonts in servlet?

Problem to displaying hindi fonts in servlet?

Scheduled Pinned Locked Moved Web Development
helpjavahtmlquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Niranjan Chouhan
    wrote on last edited by
    #1

    0 down vote favorite I am using UTF-8 encoding to display hindi fonts in servlet but hindi fonts are displaying in following format - शपथ à¤à¤¯ à¤à¤° à I am using following code- response.setContentType("text/html; charset=UTF-8"); StringWriter writer = new StringWriter(); t.merge(context, writer); String s = writer.toString(); in servlet response.getCharacterEncoding() // it is showing ISO-8859-1 by default and i have set both character encoding UTF-8 and ISO-8859-1 in both jsp and servlet but problem was not resolved. One thing is more, i am using mozila firefox and in it character encoding is Unicode. is there any effect on our output because of mozila's character encoding. Please help me?

    J 2 Replies Last reply
    0
    • N Niranjan Chouhan

      0 down vote favorite I am using UTF-8 encoding to display hindi fonts in servlet but hindi fonts are displaying in following format - शपथ à¤à¤¯ à¤à¤° à I am using following code- response.setContentType("text/html; charset=UTF-8"); StringWriter writer = new StringWriter(); t.merge(context, writer); String s = writer.toString(); in servlet response.getCharacterEncoding() // it is showing ISO-8859-1 by default and i have set both character encoding UTF-8 and ISO-8859-1 in both jsp and servlet but problem was not resolved. One thing is more, i am using mozila firefox and in it character encoding is Unicode. is there any effect on our output because of mozila's character encoding. Please help me?

      J Offline
      J Offline
      jinzai
      wrote on last edited by
      #2

      I think that you are using an incorrect encoding. UTF-8/ISO-8859-1 are only capable of encoding 256 characters. How many characters are in the Hindi character set? I assume that there are more than 256 and that you are not aware of the fact that those encodings are for character sets like ASCII -- not for language with many characters, glyphs, ligatures, etc. So -- they work for English, but not much else. XML uses UTF-8 because it uses ASCII, for example. I would recommend that you use UTF-16, but...let me research this for you. I assume that this notion is new to you -- is Hindi your native language? Mine is English of course and you know we use ASCII and UTF-8 because we only have 26 letters to use and punctuation and our character set fits into the UTF-8 encoding and many of us are unaware of any other encoding, either. Most of the rest of the world use UTF-16 and UTF-32 -- so this issue is unknown to people that only write code that is in one encoding. I will research the encoding that you need and come back and edit this reply -- we can get you fixed without much trouble, I think.

      1 Reply Last reply
      0
      • N Niranjan Chouhan

        0 down vote favorite I am using UTF-8 encoding to display hindi fonts in servlet but hindi fonts are displaying in following format - शपथ à¤à¤¯ à¤à¤° à I am using following code- response.setContentType("text/html; charset=UTF-8"); StringWriter writer = new StringWriter(); t.merge(context, writer); String s = writer.toString(); in servlet response.getCharacterEncoding() // it is showing ISO-8859-1 by default and i have set both character encoding UTF-8 and ISO-8859-1 in both jsp and servlet but problem was not resolved. One thing is more, i am using mozila firefox and in it character encoding is Unicode. is there any effect on our output because of mozila's character encoding. Please help me?

        J Offline
        J Offline
        jinzai
        wrote on last edited by
        #3

        Aye...I do not envy you at all here. Some things that might be going on and to help you get a 'handle' on this... The StringWriter -- make sure it is UTF-8 and about Firefox -- when all you have been told is that an encoding is Unicode -- it is usually UTF-16 by default (At least that is the case for VisualStudio here in the US, perhaps for FF it is UTF-8, but who knows? Maybe look deeper in the settings for FF to see if it is specified somewhere.) For example I have encountered a case where a TextWriter defaults to UTF-16 and you have to make that UTF-8 if you want to write valid XML for a schema that is already UTF-8. The class that your StringWriter is derived from might need to be coerced to be UTF-8, for example. Could there be BOMs in the text? What are the NUMERIC values of the bytes in that string? BOMs in documents usually get interpreted as strange sequences, like this one:  . The values for a BOM would be 0xef 0xbb 0xbf and they would be the first 3 bytes of a document. Java uses modified UTF-8 for some things (object serialization and literal strings in classes) and was that string serialized using Java? If so, it is not UTF-8 -- it is modified UTF-8. Modified UTF-8 does not use 0x00 as the null terminator -- it uses 0xc0 0x80. UTF-8 can be guaranteed by using an OutputStreamWriter for serialization into your request stream.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups