• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Internationalization question

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to get some japanese text to display in a jsp page. I have a japanese UTF font on my computer and can correctly display japanese web sites.
Here is what I am trying:
When i post to a servlet, i create a new Locale
Locale myLocale = new Locale("ja", "JP");
then in my servlet, i use the servlet response to set the Locale
response.setLocale(myLocale);
my jsp has this header line:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
The jsp page uses a resource bundle with th following key/vlaue:
name=\u3088\u3046\u3053\u305d
When i try to get the value for name key out of this resource, i just get ???. I know i am getting the right resource bundle becuase I can change it to something in english and it works.
What am I missing to get this to work?
Tbanks
Brian
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It has been three years since I implemented support for Japanese in JSP. Let me try to help you out.
Make sure your browser can display Japanese characters correctly. You can hit any Japanese site and see if it works right.
Make sure your browser understands UTF. Try Shift-JIS for content type.
Have some simple jsp with preset content type to Japanese. I had troubles with JRun setting it dynamically. Tomcat did not have that problem.
I used this book, which helped:
CJKV Information Processing
Chinese, Japanese, Korean & Vietnamese Computing
CJKV book
Also, Jason Hunter book "Java Servlet Programming" has very good chapter on reading characters from html form into Java code.
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I am able to see Japanese text in my browser. I tried the test on servlets.com and the link for the Japan test worked.
I downloaded the servlet code, deployed in Tomcat and it worked. Now I changed the code to forward to a .jsp and moved the the out.println() statements to the jsp. The browser showed ??? for the japanese characters.
Now, i added
<% response.setContentType("text/html; charset=Shift_JIS"); %> to my jsp and it worked.
So now my question is if you set the content type in the servlet to the correct charset, why do you have to duplicate that in the jsp in order for the browser to display it correctly?
Thanks
Brian
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am a bit confused.
If you are using JSP for dynamic content generation why would you set encoding in servlet or vice-versa ?
Whichever of them generates the page being displayed to user, has to set the proper content type and encoding.
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought if you set a header or something similar in the servlet, since i was FORWARDING the request/response to the jsp (using the RequestDispatcher, hence using the same request/response), it would use the what got set by the servlet.
Sorry for the confusion
 
Michael Bronshteyn
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the servlet java code which Servlet container generates using your jsp ( you can find it in the work directory for tomcat ). It sets content type to default. I think that if you don't enforce content type to Shift-JIS, you will have it set back to default ISO-8859-1 by container.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic