Connector
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
当在Connector中添加 URIEncoding="UTF-8" 后,servlet中不设置编码request.setCharacterEncoding("UTF-8");
get方法能解决乱码问题
但post方法不能解决
当post方法中添加设置编码后,乱码问题就解决了.
答案:
此种方法下
get 方法不需要request.setCharacterEncoding("UTF-8");
post 方法需要request.setCharacterEncoding("UTF-8");
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" useBodyEncodingForURI="true" />
当在Connector中添加 useBodyEncodingForURI="true"后,servlet中不设置 编码 request.setCharacterEncoding("UTF-8");
get post 方法均乱码
当servlet中设置编码 request.setCharacterEncoding("UTF-8");后
get post编码问题均都解决了
答案:
此种方法下:
get post方法中都需要request.setCharacterEncoding("UTF-8");
本文介绍了如何通过调整Connector配置(如添加URIEncoding和useBodyEncodingForURI属性)来解决GET和POST方法在处理包含非ASCII字符的HTTP请求时出现的乱码问题。此外,文章还强调了在特定情况下,即使调整了Connector配置,仍需要在Servlet中手动设置request的字符编码。
822

被折叠的 条评论
为什么被折叠?



