Reputation: 97
Actucally I am not sure that it is the problem caused by Tomcat.I had to deal with some Chinese words(encode in UTF-8).When I debug the program on eclipse with "Run on server",it will return the expected result.But when I export it to war package and run on tomcat, then all the Chinese words will showed in GBK, and can not be read.I do not know where the problem is.Could anyone tell me how to solve it?
Upvotes: 0
Views: 2347
Reputation: 1350
besides the answer by elkorchi, you also need the filter added in web.xml
<filter>
<filter-name>charsetFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
above works if you use spring framework, otherwise you need write your own filter like this and change the class in the xml config accordingly,
see the blog for details: enter link description here
Upvotes: 1
Reputation: 2048
You need to do several changes to make the UTF-8 as your default encoding character :
<%@page contentType="text/html; charset=UTF-8" %>
for the usual JSP pages and <jsp:directive.page contentType="text/html; charset=UTF-8" />
for the pages in XML syntax (aka JSP Documents).response.setContentType("text/html; charset=UTF-8")
or response.setCharacterEncoding("UTF-8")
.For more info see this
Upvotes: 1