I currently use
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
in my jsp page.
And when I get data from textbox using request.getParameter("...");
it retrieves data like that öÉ?É?É?öİ
. I saw this problem when I used characters that are not english chars. I add URIEncoding="UTF-8"
to server.xml
in tomcat. But it retrieved the same (öÉ?É?É?öİ)
. How to solve it?
Thank you
EDIT
Thanks for your answers. I tried a few things, but nothing has fixed the problem.
Here's what I've done:
I added
<Connector URIEncoding="UTF-8" .../>
in server.xml.<meta ... charset=utf-8>
tag is ok and I triedrequest.setCharacterEncoding("UTF-8");
- I also tried
<filter>
tag in web.xml
None of these actions fixes the problem. I'm wondering if there's something else wrong with this...(remembering: I used <form method='post'>
. I click submit button and when I get data using request.getParameter("..")
the format of this data is not the correct format. )
May be because the actual character encoding is not UTF-8 ? If the characters itself are encoded in some other format then we just can't label them as UTF-8.
Try decoding them by giving various charset and see which one gives proper result. I think the input character encoding is latin1(ISO-8859-1). If yes, follow below code
You can try this code in your Servlet
You should try it
There is another place you can check. Did you include following declaration in your JSP file?
I think the problem is that browser still sends requests using default ISO-8859-1, which is the standard charset if not declared.
You can also check the HTTP headers received from server to make sure the correct charset is sent back.
Essentially the cleanest way to do it is to use Unicode in your property files and/or code if need be (not adviced).
This way you avoid all encoding issues, since your programm only has deal with ASCII code, the proper reprenstation is then handeled entierly by the client side and you do not have to worry about the standard os encoding or enviorment encoding.
You can also try adding the following filter at web.xml:
Hope this help