把这句String temp=new String(temp_t);
改成这样试试看String temp=new String(tem_t,"gb2312");

解决方案 »

  1.   

    String temp_p=str;
    byte[] temp_t=temp_p.getBytes("ISO8859-1");
    String temp=new String(temp_t,"gb2312");
    return temp;
      

  2.   

    nickname="影落寒潭";
    sign="欲下未下风悠扬,影落寒潭三两行";
    goodfriend="新蓝";
    象这种写死在jsp里面的中文在运行的时候是unicode编码的字符流。byte[] temp_t=temp_p.getBytes("ISO8859-1");
    String temp=new String(temp_t);
    你就把unicode编码的字符流用ISO-8859-1来解码(decode)成字节流,然后用gbk编码(encode)称字符流。(如果你是中文操作系统的话,默认charset就是gbk)。所以就会出现乱码。你的代码中只有newfriend需要用这个函数来转换,因为他是ISO-8859-1编码的字符流。
      

  3.   

    这里有一个比较简单的方法
    写一个过滤器:如SetCharacterEncodingFilter.java
    package 所在包;
    import java.io.IOException;import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    public class SetCharacterEncodingFilter implements Filter {    protected String encoding = null;    protected FilterConfig filterConfig = null;    protected boolean ignore = true;    public void destroy() {        this.encoding = null;
            this.filterConfig = null;    }    public void doFilter(ServletRequest request, ServletResponse response,
                             FilterChain chain)
    throws IOException, ServletException {        if (ignore || (request.getCharacterEncoding() == null)) {
                String encoding = selectEncoding(request);
                if (encoding != null)
                    request.setCharacterEncoding(encoding);
            }        chain.doFilter(request, response);    }
        public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig;
            this.encoding = filterConfig.getInitParameter("encoding");
            String value = filterConfig.getInitParameter("ignore");
            if (value == null)
                this.ignore = true;
            else if (value.equalsIgnoreCase("true"))
                this.ignore = true;
            else if (value.equalsIgnoreCase("yes"))
                this.ignore = true;
            else
                this.ignore = false;    }
        protected String selectEncoding(ServletRequest request) {        return (this.encoding);    }
    }写完以后,在web.xml里面加上
    加在<web-app>下面
    <filter> 
      <filter-name>Set Character Encoding</filter-name>
      <filter-class>包名.SetCharacterEncodingFilter</filter-class>
      <init-param>
        <param-name>encoding</param-name>
        <param-value>gb2312</param-value>
      </init-param>
    </filter>  
    <filter-mapping>
      <filter-name>Set Character Encoding</filter-name> 
      <url-pattern>/*</url-pattern>
        </filter-mapping>
    就这么两步,如果你用转换方法来做的话.可能操作数据库的过程中还会出现乱码.这个方法不会出现.我也是用这个方法.
      
      

  4.   

    你的getStr()有点问题
    <%!
    public String getStr(String str)
    {
    try
    {
    String temp_p=str;
    byte[] temp_t=temp_p.getBytes("ISO8859-1");
    String temp=new String(temp_t,“gbk”);
    return temp;
    }
    catch(Exception e)
    {
    //to do nothing  
    }
    return "null";
    }
    %>
      

  5.   

    在前面加上<% request.setCharacterEncoding("GBK"); %>一般的乱码问题都会解决。
      

  6.   

    主要是在你得到各种参数的以后,要调用你所写的函数,
    public String getStr(String str)
    {
    try
    {
    String temp_p=str;
    byte[] temp_t=temp_p.getBytes("ISO8859-1");
    String temp=new String(temp_t);
    return temp;
    }
    catch(Exception e)
    {
    //to do nothing  
    }
    return "null";
    }
    这个函数的作用就是转化类型的:)