Bean中的字符串变量乱码!
是这样的,在Bean中有一个这样子的变量:
String serverStart = new String();
serverStart = DateFormat.getDateInstance(DateFormat.LONG).format(date);
在JSP页在有声明<%@page contentType="text/html;charSet=GB2312"%>
但是取出Bean中的这个serverStart变量显示在网页上出来为:
------------
2005?2?5?
------------
这个问题怎么解决呢,谢谢!
问题点数:40、回复次数:4Top
1 楼smilelhh(blue)回复于 2005-02-05 19:54:59 得分 15
public static String chineseChg(String s)
{
String s1 = "";
try
{
if(s == null){
s = "";
}
s1 = s.trim();
byte abyte0[] = s1.getBytes("ISO8859-1");
s1 = new String(abyte0);
}
catch(Exception e)
{
System.err.println("HandleString.chineseChg Error," + e.getMessage());
}
return s1;
}
Top
2 楼MilanmilanRain(永远的红黑军团)回复于 2005-02-05 20:42:39 得分 10
这样做太麻烦啦!只要在最开始加入request.setCharacterEnconding("GBK"); 这样就可以拉! 你那个头文件是设置客户端显示的,你要传的参数是在服务器端,应该设置一下服务器端的语言!保证可以!Top
3 楼qileroro()回复于 2005-02-05 22:40:10 得分 0
怎么用啊,我在JSP文件里加入
<%request.setCharacterEncoding("gbk");%>
不管用啊?Top
4 楼newsea008(J-LOVE)回复于 2005-02-06 16:46:40 得分 15
<%
Date date = new Date();
String nowTime = date.toLocaleString();
%>
<td><%=nowTime%>
</td>Top





