I have this Web Application in JSP running on JBoss Application Server. I am using Servlets for friendly urls. I\'m sending search parameters through my JSP\'s and Servlets.
The problem is that the information sent by the browser hasn't got a well-defined encoding and there's no way in HTTP to specify it.
Luckily most browsers will use the encoding of the page that contains the form. So if you use UTF-8 in all your pages, then most browsers will send all data in UTF-8 encoding as well (and your examples show that that's exactly how it is sent).
Unfortunately the most common Java application servers don't really handle the case (can't blame them, it's mostly guesswork anyway).
You can tell your application server to treat any input as UTF-8, by calling
request.setCharacterEncoding("UTF-8");
Based on your coding style and the frameworks you use, it might be to late when the control flow reaches your code, so it might be possible to do that in a javax.servlet.Filter
.
Just a wild guess. Try this inside your JSP/Servlet:
if(request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
You need to be sure that the correct encoding is passed to your servlet.
There are three layers to configure. From what you've described, it sounds like your problem lies in the database configuration.
JSP
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
HTML
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
JSP
<%
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("NAME");
%>
Same type of thing in a Servlet. See JBoss specific solution as well as complete server independent solution in this answer.
You may be losing the character information at the database level. Check to make sure your database encoding is UTF-8 also, and not ASCII.
For a complete discussion of this topic, refer to Java article Character Conversions from Browser to Database.
response.setCharacterEncoding("UTF-8");
We had a similar problem. It was solved when all JSPs have been saved with the UTF-8 BOM.
Check out the connecter setting in your tomcat config. There is an option (URIEncoding) you can set to treat URIs as UTF-8. By default they are treated as ISO-8859-1.