大家好,有个javascript的中文乱码问题想请大家帮我解决一下   javascript   <script language="javascript" type="text/javascript" charset="gbk">
     function Export(repFileUrl, repId, displayname){
       window.location.href="download.action?repFileUrl="+repFileUrl+"&repId="+repId + "&displayname=" + displayname;
    }       </script>    downloadAction.java    public class UpDownAction extends ActionSupport {

private String repFileUrl;
private Long repId;
private String displayname; public String getRepFileUrl() {
return repFileUrl;
} public void setRepFileUrl(String repFileUrl) {
this.repFileUrl = repFileUrl;
} public Long getRepId() {
return repId;
} public void setRepId(Long repId) {
this.repId = repId;
} public String getDisplayname() {
return displayname;
} public void setDisplayname(String displayname) {
this.displayname = displayname;
} public String download(){
System.out.println(repFileUrl + repId + displayname + "-------------------");
return SUCCESS;
}}

解决方案 »

  1.   

    看看这个,希望对你有帮助:http://blog.csdn.net/BearRui/archive/2008/10/07/3027156.aspx
      

  2.   

    估计你的软件编码是iso的每有改成gbk才会有这个问题。
      

  3.   

    转码,我这里有一个转码的类,给你,记得给分啊!
    package db;import java.io.UnsupportedEncodingException;public class ChangeChar { public ChangeChar() {
    } public static String Char(String str) {
    String value = "";
    String check = System.getProperty("os.name").toLowerCase();
    if (str != null)
    try {
    if (check.indexOf("win") != -1) {
    value = new String(str.getBytes("ISO-8859-1"));
    } else {
    value = new String(str.getBytes(), "GB2312");
    }
    } catch (UnsupportedEncodingException ex) {
    ex.printStackTrace();
    }
    return value;
    } public String gb2iso(String qs) {
    try {
    if (qs == null)
    return "NULL";
    else
    return new String(qs.getBytes("gb2312"), "iso-8859-1");
    } catch (Exception e) {
    }
    return "NULL";
    }

    public String Convert(String s){ String result = null; byte[] temp = null ; try {
    temp = s.getBytes("iso-8859-1");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } try {
    result =  new String(temp,"utf-8");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    return result; }

    public String Convert1(String s){ String result = null; byte[] temp = null ; try {
    temp = s.getBytes("utf-8");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } try {
    result =  new String(temp,"iso-8859-1");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    return result; }}
      

  4.   

    转码,我这里有一个转码的类,给你,记得给分啊!
    package db;import java.io.UnsupportedEncodingException;public class ChangeChar { public ChangeChar() {
    } public static String Char(String str) {
    String value = "";
    String check = System.getProperty("os.name").toLowerCase();
    if (str != null)
    try {
    if (check.indexOf("win") != -1) {
    value = new String(str.getBytes("ISO-8859-1"));
    } else {
    value = new String(str.getBytes(), "GB2312");
    }
    } catch (UnsupportedEncodingException ex) {
    ex.printStackTrace();
    }
    return value;
    } public String gb2iso(String qs) {
    try {
    if (qs == null)
    return "NULL";
    else
    return new String(qs.getBytes("gb2312"), "iso-8859-1");
    } catch (Exception e) {
    }
    return "NULL";
    }

    public String Convert(String s){ String result = null; byte[] temp = null ; try {
    temp = s.getBytes("iso-8859-1");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } try {
    result =  new String(temp,"utf-8");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    return result; }

    public String Convert1(String s){ String result = null; byte[] temp = null ; try {
    temp = s.getBytes("utf-8");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    } try {
    result =  new String(temp,"iso-8859-1");
    } catch (UnsupportedEncodingException e) {
    // TODO 自动生成 catch 块
    e.printStackTrace();
    }
    return result; }}
      

  5.   

    在客户端使用encodeURI,将参数转为iso编码
    服务器端再转换为相应的编码java.net.URLDecoder.decode
      

  6.   

    js这样写<script language="javascript" type="text/javascript" charset="gbk">
        function Export(repFileUrl, repId, displayname){
          window.location.href="download.action?repFileUrl="+repFileUrl+"&repId="+repId + "&displayname="     + encodeURIComponent(displayname);
        }   
    </script>
     acrion里写上displayname= new String(displayname.getBytes("ISO-8859-1"), "UTF-8");
    System.out.println(displayname);试试
      

  7.   

    jsp页头--->
    <%@ page language="java"  pageEncoding="UTF-8"%> 
    在类方法里:
     String dispname = new String(request.getParameter("displayname").trim().getBytes("ISO8859-1"),"UTF-8");
    dispname =java.net.URLDecoder.decode(dispname ,"UTF-8") ;试验下,祝你好运