jsp中使用URLEncoder解决乱码问题

时间:2025-02-14 19:01:24

以下提供两种解决方法:

1. 在传参数之前先把参数进行转码:(param);
取值时用语句(param);再转回中文


例如:
<%@ page contentType="text/html;charset=gb2312" %>

<a href="?url=<%=("汉字","GB2312")%>">点击这里</a>


<%
if(("url")!=null)
{

str=("url");
str=(str,"GB2312");
str=new String(("ISO-8859-1"));
(str);
}

%>

若,字符编码为utf-8也可以实现.或者在此段代码中,不写出字符编码也可以(只写一个参数)。

 

2. 在你的Tomcat目录-->conf目录-->里找出这段:
<Connector
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"
<!--在里边加上这个参数-->
URIEncoding="gb2312"
/>