jsp解决中文乱码问题

---------------------- jsp解决中文乱码问题-----------------------------

 

我们要统一编码,比如UTF-8

 

jsp头信息设置

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

 

项目工程编码设置

 

实在不行设置request和response编码

request.setCharacterEncoding("UTF-8");

response.setContentType("text/html;charset=UTF-8");

response.setCharacterEncoding("UTF-8");

 

Get方式中文乱码在tomcat-config-server.xml中元素connector中添加URIEncoding=”UTF-8”

<Connector port="8080"

maxThreads="150" minSpareThreads="25" maxSpareThreads="75"

enableLookups="false" redirectPort="8443" acceptCount="100"

debug="0" connectionTimeout="20000" useBodyEncodingForURI="true"

disableUploadTimeout="true" URIEncoding=”UTF-8”/>

 

 

Post方式中文乱码在servlet代码中添加request.setCharacterEncoding("UTF-8");

 

字符串转码

new String(username.getBytes("ISO-8859-1"), "UTF-8")

 

eclipse中设置jsp的默认编码

 

猜你喜欢

转载自blog.csdn.net/weixin_41547486/article/details/81476186