0

I have a java web project that use Tomcat as server .My problem is when I want to use UTF-8 characters it don't show them correctly.

I mean when I use the UTF-8 characters and run my servlet the characters in browser are not correct.and as I wand to use the in a xml page the page can't be shown.I did it with both firefox and internet explorer but I saw no change.

can anyone tell me what changes I should do in Tomcat and my project to correct this problem?

4

2 に答える 2

1

There are multiple things to look at:

  • jsp encoding should be UTF-8 (the encoding of the file - check that in your IDE/editor)
  • you have to send the appropriate header - response.setCharacterEncoding(..) in a servlet and <%@ page pageEncoding="utf-8" %>
  • if you want to use utf in the URL, you'd need to configure URIEncoding="utf-8" in tomcat's server.xml
  • if you have database access, make sure you are communicating properly with it, by setting utf-8 as the communication encoding. Also, make sure your database is using utf-8
于 2012-08-29T12:59:21.230 に答える
0

I solved this problem by:

  1. Adding a filter to my project to encode the request and response strings to UTF-8 using:

    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");
    
  2. Configuring URIEncoding="utf-8" in Tomcat's server.xml.

Thanks to all of you who helped me to solve it.

于 2012-09-04T09:21:52.013 に答える