jsp与xmlhttp在IE5.0中出现乱码!请大家帮帮忙!

andrawu 02-12-04

jsp与xmlhttp在IE5.0中出现乱码!而在IE6.0中没有任何问题!是什么原因?
有没有方法在xmlhttp中设置字符集,本人对xml不是很了解,请大家帮忙了。
谢谢!
下面是例子。在IE6.0中正常,在IE5.0中出现乱码。


test.html

<script>
function getWriter(sId){
var sFile = "http://"+location.host+"/test/test.jsp?id="+sId ;
document.all.t.value=SendHttp(sFile) ;
}
function SendHttp(sLocation)
{
var xmlhttp = new ActiveXObject(
"Microsoft.XMLHTTP");
xmlhttp.Open(
"POST", sLocation, false);
try
{
xmlhttp.Send(
"<root></root>");
}
catch (exception)
{
alert(
"服务器忙!") ;
}
try
{
var sStr=xmlhttp.responseText ;
}
catch (exception)
{
if (exception.description=='系统错误: -1072896748。') ;
{
sStr=
"" ;
}

}
return sStr ;
}
</script>
<BODY BGCOLOR=
"#FFFFFF">
书名:<select name=s onchange=getWriter(this.value);>
<option></option>
<option value=0001><<笑傲江湖>></option>
<option value=0002><<朝花夕拾>></option>
<option value=0003><<小李飞刀>></option>
</select>
作者:<input type=text name=t>
</BODY>

test.jsp
<%@ page contentType=
"text/html;charset=gb2312"%>
<%
String sId = request.getParameter(
"id")==null?"":request.getParameter("id") ;
String[] aBookId = new String[]{
"0001","0002","0003"} ;
String[] aBookWriter = new String[]{
"金庸","鲁讯","古龙"} ;
String sWriter =
"" ;
for(int i=0;i<aBookId.length;i++)
if(sId.equals(aBookId[i])){
sWriter = aBookWriter[i] ;
break ;
}
out.println(sWriter) ;
%>

banq
2002-12-04 15:27

不能再估计低版本的问题,否则太累了。

andrawu
2002-12-05 14:59

呵呵,这样就可以了。


<script>
function getWriter(sId){
var sFile = "http://"+location.host+"/test/test.jsp?id="+sId ;
document.all.t.value=SendHttp(sFile) ;
}
function SendHttp(sLocation)
{
if (navigator.onLine==false)
{
return
"你现在处于脱机状态,请联机后再试!"
}
var xmlhttp = new ActiveXObject(
"Microsoft.XMLHTTP");
xmlhttp.Open(
"POST", sLocation, false);
try
{
xmlhttp.setRequestHeader(
"Content-Type","text/xml")
xmlhttp.Send(
"<root></root>");
}
catch (exception)
{
alert(
"服务器忙!") ;
}
try
{
var sStr=xmlhttp.responseXML.xml ;
alert(sStr) ;
}
catch (exception)
{
if (exception.description=='系统错误: -1072896748。') ;
{
sStr=
"" ;
}

}
return sStr ;
}
</script>
<BODY BGCOLOR=
"#FFFFFF">
书名:<select name=s onchange=getWriter(this.value);>
<option></option>
<option value=0001><<笑傲江湖>></option>
<option value=0002><<朝花夕拾>></option>
<option value=0003><<小李飞刀>></option>
</select>
作者:<input type=text name=t>
</BODY>

test.jsp
<%@ page contentType=
"text/xml;charset=gb2312"%>
<%
String sId = request.getParameter(
"id")==null?"":request.getParameter("id") ;
String[] aBookId = new String[]{
"0001","0002","0003"} ;
String[] aBookWriter = new String[]{
"金庸","鲁讯","老舍"} ;
String sWriter =
"" ;
for(int i=0;i<aBookId.length;i++)
if(sId.equals(aBookId[i])){
sWriter = aBookWriter[i] ;
break ;
}
sWriter =
"<?xml version=\ŕ.0\" encoding=\"GB2312\"?><a>"+sWriter+"</a>" ;
out.println(sWriter) ;
System.out.println(sWriter) ;
%>

fantasia
2003-07-24 16:10

怎么我的tomcat里执行test.html,然后改变下拉框里的值就该页面就会没有响应呢?再问一下在test.jsp有没有处理xmlhttp send过来的数据

kisan
2003-07-24 17:18

kisan3618410x03.htm

2Go 1 2 下一页