请教JSP中的汉字问题
<%
String tempstring="这里是汉字";
%>
<%= tempstring %>
显示为乱码,如何解决?
问题点数:50、回复次数:6Top
1 楼topmint(秋景)回复于 2003-01-05 12:04:41 得分 0
<%@ page contentType="text/html;charset=gb2312"%>
Top
2 楼zxhong(红透半边天)回复于 2003-01-05 12:11:16 得分 0
可能由于tomcat版本过低,楼上的方法如果不行
改为:
<%@ page contentType="text/html;charset=ISO8859_1"%>
Top
3 楼beyond_xiruo(CorruptionException)回复于 2003-01-05 12:22:47 得分 0
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">Top
4 楼ishallwin()回复于 2003-01-07 17:22:59 得分 0
在TOMCAT中正常,但传到虚拟主机上不正常!
虚拟主机很好的处理了网页之间的汉字传输问题,但在同一个网页中则存在如上现象,并且<%@ page contentType="text/html;charset=ISO8859_1"%>中的"ISO8859_1"不能改成gb2312,否则网页出错.
Top
5 楼ken1024(KEN)回复于 2003-01-07 18:59:14 得分 30
/**
* 中文转码
*/
public static String isoToGBK(String aISO) {
try {
return new String(aISO.getBytes("iso8859-1"), "GBK");
}
catch (Exception e) {
return "转码错误!";
}
}Top
6 楼zhx_232(笨狗熊妹妹)回复于 2003-01-08 19:19:51 得分 20
在页面的开始加上:
<%@ page contentType="text/html;charset=gb2312"%>
在得到变量是用下面的函数进行转换
public String chinese(String source) {
try
{
String _temp = "";
byte[] _byte = source.getBytes("iso-8859-1");
_temp = new String(_byte, "gb2312");
source=_temp;
}
catch (Exception ex)
{
System.out.println(ex.toString());
}
returnTop




