1 回答
This is a simple filter that will do it. You just need to add this filter to your web.xml before the struts2 filter.
public class CharacterEncodingFilter implements Filter
{
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain next)
throws IOException, ServletException
{
String encoding = request.getCharacterEncoding();
if (encoding == null || encoding.length() == 0)
{
request.setCharacterEncoding("UTF-8");
}
next.doFilter(request, response);
}
}
not sure though it will work as have not tried it myself :)
Update
even after the above Filter i was also facing the same issue and after some digging it as per my understanding is due to the fact that application server will by default use the ISO 8859-1 character encoding.
i added the following entry in my tomcat server.xml file
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
URIEncoding="UTF-8" // this is what i added
and now i am able to see the proper character in my jsp page.same we have to do with java default encoding.
read this great article unicode-how-to-get-characters-right by BalusC.
hope this will help you.