我把%catalina_home%/conf/server.xml里的connector(port默认为8080,我现改为8081了)元素里加了一个参数URIEncoding="utf-8",
随后,我写了一个jsp页面如下:
<%@ page contentType="text/html;charset=gb2312" %>
<% 
String value=(String)request.getParameter("name");
out.print(new String(value.getBytes("utf-8"),"gb2312"));
out.print(new String(value.getBytes("ISO-8859-1","gb2312"),%>
${param.name}--------------------------------
在浏览器里写的url为http://localhost:8081/TagFile/taguse.jsp?name=张三
用第一个out输出是一堆乱码,第二个out和EL输出的是四个?号.
请大家帮我分析一下其原因过程啊.
-------------------------
我都整了一天啦,怎么都不成啊.

解决方案 »

  1.   


    <%@ page contentType="text/html;charset=gb2312" %>
    <% 
    request.setCharacterEncoding("GBK"); //设置字符集
    String value=(String)request.getParameter("name");
    out.print(value);%>
      

  2.   

    试试这个
    <%@ page contentType="text/html;charset=utf8" %>
    <% 
    String value=(String)request.getParameter("name");
    out.print(new String(((String)str).getBytes("ISO-8859-1"),"GBK"));
    %>
      

  3.   

    试试这个
    <%@ page contentType="text/html;charset=utf8" %>
    <% 
    String value=(String)request.getParameter("name");
    out.print(new String(((String)value).getBytes("ISO-8859-1"),"GBK"));
    %>
      

  4.   

    <%!
    String trans(Object chi){
         return trans(chi.toString());
        }
    String trans(String chi){
    String result=null;
    byte temp[];
    try{
    temp=chi.getBytes("iso-8859-1");
    result=new String(temp);
    }
    catch(UnsupportedEncodingException e){
    System.out.println(e.toString());
    }
    return result;
    }
    %>
    <%=name.trans(request.getParameter("name"))%>
      

  5.   

    建议全部采用UTF-8,连接池characterEncoding,8080端口的URIEncoding还有页面全部采用UTF-8,再不行的话加一个Filter
      

  6.   

    eric0cn(IPHelper4.2)
    试试这个
    <%@ page contentType="text/html;charset=utf8" %>
    <% 
    String value=(String)request.getParameter("name");
    out.print(new String(((String)value).getBytes("ISO-8859-1"),"GBK"));
    %>
    --------------------------------
    也没成功,
    如果把%catalina_home%/conf/server.xml中的<Connector>URIEncoding值改为"gbk"在jsp中不作转化都是可以的,
    只是我不明白,utf-8编码这个老头子,如何使它才能成啊.
      

  7.   

    利用trans函数,我都是使用它.
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.io.*"%>
    <%!String trans(String chi)
    {
    String result=null;
    byte temp[];
    try
    {
    temp=chi.getBytes("iso-8859-1");
    result=new String(temp);
    }
    catch(UnsupportedEncodingException e)
    {
    System.out.println(e.toString());
    }
    return result;
    }
    %>
    将此函数放入一个文件中,例如trans.inc中,只要在你想转换的文件中加上<%@ include file="trans.inc"%>就能使用!
    String value=(trans)request.getParameter("name");肯定成功
      

  8.   

    如果是Mysql数据库的话,安装MySQL数据库时候就指定字符集合为gbk或者gb2312,只要数据库中显示正常中文字符的话,页面肯定显示正常,哪来这么多的转换,烦死了!!
    LZ不妨试一试。