对于test.jsp
我用 http://localhost:8080/test.jsp?info=中国
和 http://localhost:8080/test.jsp?info=%D6%D0%B9%FA
访问,在页面上打印的都是乱码,英文可以正常显示,
请问我的代码如何改改,能让他们正常显示呢?
test.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page contentType="text/html; charset=GBK" %>
<title>My JSP 'test.jsp' starting page</title>
</head> <body> <script language=javascript> <%
String temp = request.getParameter("info");
%>
document.write('<%=temp%>');
</script>
</body>
</html>
我用 http://localhost:8080/test.jsp?info=中国
和 http://localhost:8080/test.jsp?info=%D6%D0%B9%FA
访问,在页面上打印的都是乱码,英文可以正常显示,
请问我的代码如何改改,能让他们正常显示呢?
test.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page contentType="text/html; charset=GBK" %>
<title>My JSP 'test.jsp' starting page</title>
</head> <body> <script language=javascript> <%
String temp = request.getParameter("info");
%>
document.write('<%=temp%>');
</script>
</body>
</html>
http://localhost:8080/test.jsp?info=%D6%D0%CE%C4
显示????
http://localhost:8080/test.jsp?info=中国
显示???ú
String s = null;
byte temp[]; if (in == null) {
System.out.println("Warn:Chinese null founded!");
return new String("");
}
try {
temp = in.getBytes("iso-8859-1");
s = new String(temp);
}
catch (Exception Ex) {
System.out.println(Ex.toString());
}
return s;
}=================================================================
写这么个方法好了,以后要取中文值只要调用这个方法就行了
找到 server.xml 中的
<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding='GBK' />
最后面加上:URIEncoding='GBK'
不过我没有试过,楼主试试!