<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>无标题文档</title>
</head><body>
中文中文
</body>
</html>按道理说UTF8是支持中文的,为什么当我打开这个网页全都是乱码????
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>无标题文档</title>
</head><body>
<form name="form1" method="post" action="">
<input type="text" name="ok">
<input type="submit" name="Submit" value="提交">
</form><%
String str = request.getParameter("ok");
if(str == null) {
str = "";
}
String str1 = new String(str.getBytes("GBK"));
%>
<%=str1%>
</body>
</html>我的系统是windows2000支持GBK
这里,我用GBK,和UTF-8都不行只能用ISO-8859-1,为什么阿?
还有String str1 = new String(str.getBytes(),"ISO-8859");
用这个构造器,竟然不起作用?
<html>
<head>
<title>无标题文档</title>
</head><body>
中文中文
</body>
</html>按道理说UTF8是支持中文的,为什么当我打开这个网页全都是乱码????
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<title>无标题文档</title>
</head><body>
<form name="form1" method="post" action="">
<input type="text" name="ok">
<input type="submit" name="Submit" value="提交">
</form><%
String str = request.getParameter("ok");
if(str == null) {
str = "";
}
String str1 = new String(str.getBytes("GBK"));
%>
<%=str1%>
</body>
</html>我的系统是windows2000支持GBK
这里,我用GBK,和UTF-8都不行只能用ISO-8859-1,为什么阿?
还有String str1 = new String(str.getBytes(),"ISO-8859");
用这个构造器,竟然不起作用?
http://bbs.gzit.org/viewthread.php?tid=184
<%@page pageEncoding="GBK" contentType="text/html; charset=GBK" %>
<%@ page contentTpe="text/html; charset=gb2312" language="java" %>这两个编码都不一样
刚忘了说我是tomcat5的String str1 = new String(str.getBytes(),"ISO-8859");
这个构造器,用不成这是怎么回事?
然后再加上String str1 = new String(str.getBytes(),"GBK");
str1的显示就没有问题了,如果写入到文件则要
FileOutputStream os.write(lsSQL.getBytes("GBK"));
不知道是不是和tomcat的版本有关
String str1 = new String(str.getBytes(),"ISO-8859");
而这个方法是先让str(ISO-8859-1)以GBK编码(system默认)然后又解码成iso-8859-1
所以有乱码,
page contentType="text/html; charset=gb2312
而这个试网页输出,和str的处理无关,所以不管改成什么jsp/servlet默认输出str依旧是iso-8859-1编码
不只我的解释是否正确,