php文件中在乱码(如a.php文件在浏览器乱码): header("Content-Type:text/html;charset=utf-8")是设置网页的。 mysql_query("set names utf-8")设置数据库的。 java中的struts:中文乱码问题一般是指当请求参数有中文时,无法在Action中得到正确的中文。Struts2中有2种办法可以解决这个问题:
l 设置JSP页面的pageEncoding=”utf-8”,就不会出现中文乱码;
l 如果JSP页面的pageEncoding=”GBK”,那么需要修改struts.i18n.encoding=GBK,在struts.xml中加入如下语句进行修改。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.i18n.encoding" value="GBK"/> …… </struts> |
上面2种方法可以解决POST请求中的中文参数,但是GET请求中的中文参数不能解决,GET请求中的中文参数的乱码需要通过修改Tomcat的server.xml文件来解决,修改如下内容,加入URIEncoding=”GBK”:
<Connector port="8080" …… URIEncoding="GBK"/>