您的位置 首页 java

JAVA学习笔记之–JSP中的中文乱码问题解决集锦

### 如果用的是Tomcat的话,看看下面是否配置正确:

(1)Tomcat 的 conf 下的server.xml文件中将

<Connector port=”8080″ protocol=”HTTP/1.1″

connectionTimeout=”20000″

redirectPort=”8443″ />

里添加上后面3个编码的设置

<Connector port=”8080″ protocol=”HTTP/1.1″

connectionTimeout=”20000″

redirectPort=”8443″

useBodyEncodingForURI=”true”

IEncoding=”utf-8″

URIEncoding=”utf-8″/>

(2)

然后在servlet中配置如下:

如果你用的是 post方式

解决方案:

request.setCharacterEncoding(“utf-8”);

response.setCharacterEncoding( “utf-8” );

get方式

String str = request.getParamers(“username”);

String newStr= new String(str.getBytes(“ISO-8859-1″),”utf-8”);

(3)jsp页面中 pageEncoding=”UTF-8″

(4)如果你用的是Eclipse或者MyEclipse的话,选择window的

preferences中的左上角的输入框中输入spelling

在spelling这个页面中看看Encoding 默认是否设置为utf-8

文章来源:智云一二三科技

文章标题:JAVA学习笔记之–JSP中的中文乱码问题解决集锦

文章地址:https://www.zhihuclub.com/181653.shtml

关于作者: 智云科技

热门文章

网站地图