|
写入时,先做encode:
public static String encode(String src) {
String result = null;
try {
result = new String(src.getBytes("gbk"), "ISO-8859-1");
} catch (UnsupportedEncodingException uee) {
System.err.println(uee);
}
return result;
}
读出时,再做decode:
public static String decode(String src) {
String result = null;
try {
result = new String(src.getBytes("ISO-8859-1"), "gbk");
} catch (UnsupportedEncodingException uee) {
System.err.println(uee);
}
return result;
}
连接时不需要指定字符集
jsp页面中:
<%
sql1="select Article_id from Article where type_id=2 or type_id=8 or type_id=13 order by Add_time desc";
DManager=DatabaseCacheManager.getInstance();
Iter=DManager.messages(sql1,0,9);
while (Iter.hasNext()) {
DbArticleMessage message = (DbArticleMessage)Iter.next();
long Id = message.getArticle_id();
String file_name=message.getFile_name();
out.print("<img src=images/ico4.gif width=12 height=12 border=0><a href='"+file_name+"?id="+Id+"'>");
out.print(new String(message.getArticle_name().getBytes("ISO-8859-1"), "gbk")+"</a>");
java.util.Date oldDate=message.getAdd_time();
if(HTML.eq(new java.util.Date(),oldDate))
out.print("<img src=images/new.gif border=0>");
out.print("<br>");
}
%> |
|