Symbol corrupted when using request.getParameter () in java
I have a web page where I am performing a search based on the text specified in a text box. This text can be in any language like Japanese, Chinese, etc. (Or any mbcs character).
Now when I enter text in japanese (or any other mbcs character), the result fills the screen (form) with some wierd characters.
Example: testテスト
turns into testãã¹ã
.
When I see the message options in Firebug (a debug tool) I can see the search string goes like testテスト
, however when I add debug statements to my code, I see that request.getParameter("searchString")
I cannot identify Japanese characters and turn them into a few strange characters.
My JSP header already has <%@ page contentType="text/html; charset=UTF-8"
I also tried to put pageEncoding="UTF-8"
in this, but it didn't help.
I tried setting the character encoding as request.setCharacterEncoding("UTF-8")
well before doing request.getParameter
, but that didn't work for me either.
After going through several forums and blogs, I also tried to set useBodyEncodingForURI=true
in <Connector>
tomcat config, but that also didn't work for me.
Can anyone suggest me something to solve this problem?
source to share
set the following encoding in each servlet / action
response.setContentType("UTF-8");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
also sets the following in the first servlet / action
for japanese
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
session.setAttribute(Globals.LOCALE_KEY, new Locale("jp", "ja_JP"));
source to share