<%@ page language="java" contentType="text/html;charset=gb2312" %>
和
String temp=new String(strName.getBytes("ISO-8859-1"),"gb2312");
这两 种方法不可以用于同一页面.
和
String temp=new String(strName.getBytes("ISO-8859-1"),"gb2312");
这两 种方法不可以用于同一页面.
<%@ page contentType="text/html;charset=gb2312" %>
<%
String a="中文";
out.println(a);
%>
通过调试,在我的jb下是可以的。
2、
String a="中文";
String temp=new String(a.getBytes("ISO-8859-1"),"gb2312");
out.println(temp);
肯定是不行的。
3、
String temp=new String(a.getBytes("ISO-8859-1"),"gb2312");
一般对于得到提交后的中文数据进行转换,因为中文经过提交时变成了内码。
4、
不知hackerning(勤学)用的是什么环境,出现了什么样的情况,你是怎么解
决呢?呵呵,如果你知道,就不考我们了嘛。
再试试这种方式?看来编码问题很成问题。
那就试试加上这个JSP的编码问题很成问题
<%@ page contentType="text/html;charset=gb2312" %>
<%
String a="中文";
out.println(a);
%>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<%@ page language="java" contentType="text/html;charset=gb2312" %> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><%String strTemp="检查是不是服务器的问题!";out.print(strTemp+"<br>");strTemp=new String(strTemp.getBytes("GBK"),"ISO8859-1");out.print(strTemp+"<br>");strTemp=new String(strTemp.getBytes("ISO8859-1"),"GBK");out.print(strTemp+"<br>");%>
</BODY>
</HTML>
用你的strTemp=new String(strTemp.getBytes("ISO8859-1"),"GBK");打印正确。我用的是weblogic
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<%@ page language="java" contentType="text/html;charset=gb2312" %> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"><%String strTemp="检查是不是服务器的问题!";out.print(strTemp+"<br>");//strTemp=new String(strTemp.getBytes("GBK"),"ISO8859-1");
strTemp=new String(strTemp);out.print(strTemp+"<br>");strTemp=new String(strTemp.getBytes("ISO8859-1"),"GBK");out.print(strTemp+"<br>");%>
</BODY>
</HTML>
这样的话,strTemp=new String(strTemp);打印也正确啊。何必非要用什么GBK参数?
问题解决了吗?
好运!
我刚试过了.
<%!
public String getStr(String str){
try{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e){
}
return "NULL";
}
%>
<%
String a="中文"
a=getStr(a);
%>
<%=a%>
试试可不可以?
很简单
1如果是request.form 传过来的汉字乱码,用getStr()处理,注意,getStr()可用于request传递过来的参数。但是不必一定要用它。
2 如果不是,request.form 传递过来的 仅仅需要
<%@page contentType="text/html;charset=GB2312" >
即可正常显示,不要用 getStr() 处理
3 如果以上 1,2 都行不通。服务器的问题,要在服务器中引入中文字符库。
<%!
public String getStr(String str){
try{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e){
}
return "NULL";
}
%>
bean.java
{……
public static final String[] provinces = {"Select...","BeiJing","广东","广西",……,"江西","港台"};
}
在jsp中调用此数组 <% = bean.provinces[i] %> 却出现中文乱码问题(不是???)。英文没有问题,什么道理吗?
resin的默认编码就是iso-8859-1,所以当然是乱码。
仔细看看你每一步可能的编译操作都将字符串转化成什么编码了。
public class test
{
public static void main(String[]args)
{
System.getProperies().list(System.out);
}
}
X:\java test
查看 file.encoding = ?
如果系统的默认编码为 GBK ,通常不会出现中文问题。
注意两点:
1。win OS 默认字符集为 GBK, Linux 默认字符集为 ISO-8859-1
2。JRE 分为英文版和国际版,国际版支持多国字符。