Archive for June, 2009
在Ubuntu下修改主机名
Jun 23rd
如何在Ubuntu下修改主机名呢?
首先编辑 /etc/hostname 文件,把文件的内容修改为你想要的主机名。
然后运行
/etc/init.d/hostname.sh start
相关文章:
How to change the hostname of a Linux system
http://www.ducea.com/2006/08/07/how-to-change-the-hostname-of-a-linux-system/
在Java中,把字符串转换成Unicode码
Jun 17th
我是碰到这样一样情况,由于我使用了jQuery.getScript(),来进行跨域,不过遇到有些浏览器的编码编码不一致,导致乱码。
这样处理的好处是,避免了乱码的问题。
只是服务器端的代码,和网上的代码一样,不过我加了个
StringUtils.leftPad()
方法处理,这样就解决了每个字符都转化为四位的Unicode编码,在浏览器端用 unescape(blogLoginInfo.nicknameUnicode.replace(/\\/g,”\%”)); 就可以解码。
服务器端转码代码如下:
/**
* 把字符转换成Unicode编码
* @param str
* @return
*/
public static String toUnicode(final String str) {
String result = "";
for (int i = 0; i < str.length(); i++) {
int charInt = str.charAt(i);
result += "\\u" + StringUtils.leftPad(Integer.toHexString(charInt), 4, "0");
}
return result;
}