- 论坛徽章:
- 0
|
至今一直没有把在JSP中出现的乱码摆平,真郁闷。
本人涉及下面的五个文件,先把各个文件的内容列出来。
======================================================================
文件 result.jsp 的内容
<%@ page contentType="text/html; charset=GBK" %>;
<%@ page language="java" %>;
<%!
public String ISO2GBK(String strvalue) {
try{
if(strvalue==null){
return null;
}else{
strvalue =new String(strvalue.getBytes("ISO8859_1"),"GBK");
return strvalue;
}
}catch(Exception e){
return null;
}
}
%>;
<meta http-equiv="Content-Type" content="text/html; charset=GBK">;
<%
String key=request.getParameter("key");
out.print("未用ISO2GBK处理:"+key+"<br>;");
out.print("使用ISO2GBK处理:"+ISO2GBK(key));
%>;
======================================================================
文件 1.jsp 的内容
<%@ page contentType="text/html; charset=GBK" %>;
<form name="form1" method="post" action="result.jsp">;
<input type="text" name="key">;
<input type="submit" name="Submit" value="send">;
</form>;
======================================================================
文件 1.htm 的内容
<meta http-equiv="Content-Type" content="text/html; charset=GBK">;
<form name="form1" method="post" action="result.jsp">;
<input type="text" name="key">;
<input type="submit" name="Submit" value="send">;
</form>;
======================================================================
文件 1.xml 的内容
<?xml version="1.0" encoding="GBK"?>;
<?xml-stylesheet type="text/xsl" href="1.xsl"?>;
<info>;
<Content>;this is xml Content</Content>;
</info>;
======================================================================
文件 1.xsl 的内容
<?xml version="1.0" encoding="GBK"?>;
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">;
<xsl:template match="/">;
<html>;
<head>;
<meta http-equiv="Content-Type" content="text/html; charset=GBK"/>;
</head>;
<body>;
<form method="post" action="result.jsp">;
<input name="key" type="text" />;
<input type="submit" name="Submit" value="send"/>;
</form>;
1.xml:<xsl:value-of select="info/Content"/>;
</body>;
</html>;
</xsl:template>;
</xsl:stylesheet>;
======================================================================
下面是我的操作过程(假设我的域名是www.abc.com)。
第一种情况:
用IE查看 http://www.abc.com/1.jsp ,在输入框中输入“中文”两字,提交后,页面显示:
在tomcat 4.1.29平台下的结果:
未用ISO2GBK处理:????
使用ISO2GBK处理:中文
在resin 3.0.3 平台下的结果:
未用ISO2GBK处理:中文
使用ISO2GBK处理:??
第二种情况:
用IE查看 http://www.abc.com/1.htm ,在输入框中输入“中文”两字,提交后,页面显示:
在tomcat 4.1.29平台下的结果:
未用ISO2GBK处理:中文
使用ISO2GBK处理:中文
在resin 3.0.3 平台下的结果:
未用ISO2GBK处理:中文
使用ISO2GBK处理:??
第三种情况:
用IE查看 http://www.abc.com/result.jsp?key=中文 ,页面显示:
在tomcat 4.1.29平台下的结果:
未用ISO2GBK处理:????
使用ISO2GBK处理:中文
在resin 3.0.3 平台下的结果:
未用ISO2GBK处理:中文
使用ISO2GBK处理:??
第四种情况:
用IE查看 http://www.abc.com/1.xml ,在输入框中输入“中文”两字,提交后,页面显示:
在tomcat 4.1.29平台下的结果:
未用ISO2GBK处理:??????
使用ISO2GBK处理:涓?枃
在resin 3.0.3 平台下的结果:
未用ISO2GBK处理:涓?枃
使用ISO2GBK处理:???
唉,看这上面出现的情况,我傻了。
同样的代码在不同平台下的运行结果不一样,要想写不需要改动就能跨平台运行的代码是不是很不方便呀;
第一到第三种情况虽然有乱码出现,但毕竟还有正常显示的情况,可是第四种情况却全乱了!!!
怎么样才是最根本的解决办法?本人现在最最关注第四种情况出现的乱码,怎么解决? |
|