对于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>

解决方案 »

  1.   

    取值之前加上request.setCharacterEncoding("gbk");
      

  2.   

    加上了,还是不行
    http://localhost:8080/test.jsp?info=%D6%D0%CE%C4
    显示????
    http://localhost:8080/test.jsp?info=中国
    显示???ú
      

  3.   

    info=后面的不是你自己写的吧???
      

  4.   

    public static String parseChinese(String in){
            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;
        }=================================================================
    写这么个方法好了,以后要取中文值只要调用这个方法就行了
      

  5.   

    一个一劳永逸的方法就是更改Tomcat\conf\server.xml
    找到 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'
    不过我没有试过,楼主试试!