这是我的JSP页面代码
<%@ page contentType="text/html;charset=gbk" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<body> <%@ page import="com.tribe.constant.CodeFilter" %> <%
String a = "how are you你们好!";
String b = "howareyou你们好!";
String c1 = "";
String c2 = "";
c1 = CodeFilter.strByteCopy(a,11);
c2 = CodeFilter.strByteCopy(b,11);
int len1 = c1.length();
int len2 = c1.length();
%>
c1:<%=c1%><br>
c2:<%=c2%><br>
len1:<%=len1%><br>
len2:<%=len2%><br>
</body>
</html>
这是CodeFilter的strByteCopy方法代码
public static String strByteCopy(String str,int nEnd)
{
if(nEnd==0)
return "";
byte[] byteStr=str.getBytes();
int k=byteStr.length;
String strSub=new String(byteStr,0,nEnd<k?nEnd:k);
if (nEnd<k) strSub = strSub + "..";
return strSub;
} 问题是这个:
我在本地的测试结果(WINDOWS): c1:how are you..
c2:howareyou你..
len1:13
len2:13 但是我传到LINUX服务器上的结果: c1:how are you..
c2:howareyou..
len1:13
len2:13
问题:c2的结果不同,请问这个为什么???诚请大家指教!
<%@ page contentType="text/html;charset=gbk" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<body> <%@ page import="com.tribe.constant.CodeFilter" %> <%
String a = "how are you你们好!";
String b = "howareyou你们好!";
String c1 = "";
String c2 = "";
c1 = CodeFilter.strByteCopy(a,11);
c2 = CodeFilter.strByteCopy(b,11);
int len1 = c1.length();
int len2 = c1.length();
%>
c1:<%=c1%><br>
c2:<%=c2%><br>
len1:<%=len1%><br>
len2:<%=len2%><br>
</body>
</html>
这是CodeFilter的strByteCopy方法代码
public static String strByteCopy(String str,int nEnd)
{
if(nEnd==0)
return "";
byte[] byteStr=str.getBytes();
int k=byteStr.length;
String strSub=new String(byteStr,0,nEnd<k?nEnd:k);
if (nEnd<k) strSub = strSub + "..";
return strSub;
} 问题是这个:
我在本地的测试结果(WINDOWS): c1:how are you..
c2:howareyou你..
len1:13
len2:13 但是我传到LINUX服务器上的结果: c1:how are you..
c2:howareyou..
len1:13
len2:13
问题:c2的结果不同,请问这个为什么???诚请大家指教!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货