大家好,有个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;
}}
解决方案 »
- 在tomcat通过,发布到WebSphere报http 500错误,大大帮忙看下啊,先谢谢了
- 大家来帮帮我!急
- jsf中,h:selectOneMenu邦定的问题!谢谢了,急,在线死等!!!
- 一个比较初级的问题!~~~~~~在线!~
- 比较深入的hibernate问题, 谢谢大家的讨论!
- 请高手们指教,弄了几天都弄不明白的问题!!!!
- 求救SOS
- 紧急问题,100分转贴!
- 原来使用jdbc-odbc for sql server2000桥,改用jdbc for sql server2000后,数据库中取出的数据中文变成了乱码?
- nginx 请求队列
- 连接access数据库出错
- IE的请求从request.getLocale()得出来的是zh_C而不是zh_CN?对国际化资源有没影响?
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; }}
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; }}
服务器端再转换为相应的编码java.net.URLDecoder.decode
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);试试
<%@ 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") ;试验下,祝你好运