This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How Solve utf-8 encoding problem  RSS feed

 
Nil. Hatamova
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I used servlet for create login session. When i  enter username and password servlet call  home.jsp page. Then all other jsp pages have same problem.i add   code for all of them. But it doesnt solve problem. Please help me
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66042
140
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nil. Hatamova wrote:But it doesnt solve problem.

What is the problem?
 
Nil. Hatamova
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Nil. Hatamova wrote:But it doesnt solve problem.

What is the problem?


It is UTF-8 encoding problem.In website i used unicode characters. But on a Tomcat server, utf-8 characters get mangled.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15985
86
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with character encoding problems is that the cause of it can be in many different places. You have to be careful and check everything:

- What character encoding are your source JSP files saved in by your IDE? Is it UTF-8 or some other encoding (maybe the default encoding of your OS which might be different than UTF-8)?
- Where does the text come from? Is it static text that's directly in the JSP file or does it come from a database or some other source?
- If it's from a database, then what character encoding does the database use? And how are you getting it from the DB? Is the character encoding handled correctly in every step?
- If it's from a Java *.properties file, you have to be aware that class java.util.Properties treats *.properties files as if they are always encoded in ISO-8859-1. If you've saved the *.properties file using any other encoding, you'll get mangled text.

In my experience, many software developers don't understand character encodings and they often end up trying to solve a character encoding problem by adding "magic lines" to their code (lines of code which they don't understand, but just hope that they solve the problem). Don't do that - it's better to learn once and for all how character encodings work, and then you don't have to rely on magic lines which you don't understand.

Here's a good article that explains character encoding: What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!