问题:URL参数为中文,String str = request.getParameter();输出???,保存到数据库也是乱码
解决:
1、配置Tomcat
<?xml version=‘1.0‘ encoding=‘GBK‘?>
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
useBodyEncodingForURI="true"
URIEncoding="UTF-8"/>
注释:encoding=‘GBK‘ 使web发布路径可以为中文,useBodyEncodingForURI="true" 和 URIEncoding="UTF-8",让tomcat统一用UTF-8编码,经测试用其它编码都有问题
2、jsp代码
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%
String param ="";
if( request.getParameter("param")!=null && !request.getParameter("param").equals(""))
param= new String(request.getParameter("param").getBytes("ISO-8859-1"),"UTF-8");
%>
时间: 2024-10-11 04:55:32