How to make the servlet accept non-ascii (Arabian, chines, etc) characters passed from JSPs?
I've tried to add the following to top of JSPs:
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
And to add the following in each post/get method in the servlet:
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
I've tried to add a Filter that executes the above two statements instead of in the servlet.
To be quite honest, these was working in the past, but now it doesn't work anymore.
I am using tomcat 5.0.28/6.x.x on JDK1.6 on both Win & Linux boxes.
Here's an example: JSP Page:
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>Push Engine</title>
</head>
<body>
Hello ${requestScope['val']}
<form action="ControllerServlet" method="POST">
<table>
<tr>
<td>ABC</td>
<td><input name="ABC" type="text" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
Servlet doGet method:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String val = "request.getParameter('ABC') : " + request.getParameter("ABC");
System.out.println(val);
request.setAttribute("val", val);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
THE PROBLEM IS: in the console, value "???" is being printed, however, the value returned backed to the JSP page containing the correct Unicode word
the "???" printed to the console is a problem in the machine that I ran this test on. I've ran the same example on another machine, and It works properly!