把平常收集到的和遇到的一些小問題列出來,以備不時之需.
也歡迎大家把自己的收藏跟貼.
import java.io.ByteArrayInputStream;
import java.io.InputStream;
String ? str ? = ? "";//add ? your ? string ? content
InputStream ? inputStream ? = ? new ? ByteArrayInputStream(str.getBytes());
2. String和數字互相轉換
1 如何將字串 String 轉換成整數 int?
? 有兩個方法:
? 1). int i = Integer.parseInt([String]); 或
????? i = Integer.parseInt([String],[int radix]);
? 2). int i = Integer.valueOf(my_str).intValue();
? 注: 字串轉成 Double, Float, Long 的方法大同小異.
2 如何將整數 int 轉換成字串 String ?
? 1.) String s = String.valueOf(i);
? 2.) String s = Integer.toString(i);
? 3.) String s = "" + i;
? 注: Double, Float, Long 轉成字串的方法大同小異.
作者: ynmc
原文地址:
http://m.tkk7.com/ynmc/archive/2006/06/26/55149.html歡迎轉載,請保留出處.
在用DWR傳輸xml文檔(document)或者節點(Element)的時候,通過DWR Debug頁面從函數中直接取返回數據時,由于DWR對于Firefox的支持度比IE好的原因,在FireFox下面能正常運行,在IE下會報[Ojbect Error]。我用DWR1.1和DWR M2兩個版本都進行了測試,都會報出同樣的錯誤。
關于這個錯誤,我已經和DWR的作者joe walker通過user-list聯系過,他表示由于時間的問題,在ie下面的確有一些bug沒有來得及處理。
同時,我又做了一些測試,發現其實這個問題確實如Joe后來回復的郵件所說,是個沒有什么意義的小問題。在IE下其實也是可以傳遞Document或者Element數據的,只是在DWR Debug頁面下,直接從函數中返回Document或者Element時,DWR彈出的顯示元素的對話框。這個時候DWR隱式的將Document或者Element對象轉換成了String,而DWR對FireFox支持的較好,沒有問題,而在IE中就會彈出Object Error錯誤。
所以對實際應用來講,這個bug完全可以忽略,因為除了debug以外,在使用中沒有任何影響。
Joe 最后回復了郵件,也給出了處理辦法,他的意思是這種情況出現的比較少,意義不大(我就是聽他說了這句話之后發現了開始自己的理解有誤,看來多與人交流是非常重要的啊。)
下面是郵件原文:
From: Joe Walker <
joseph.walker@...>
Subject:
Re: Re: [new user]problem: can't send/return DOM object?
Newsgroups:
gmane.comp.java.dwr.user
Date: 2006-06-26 08:32:37 GMT
(1 day and 48 minutes ago)
Expires: This article
expires on 2006-07-10
The DOM converter will convert from browser DOM objects to server
side DOM objects, but it wasn't designed to convert from browser
strings to SS DOM.
How do you parse a browser string into a browser DOM?
This can't be done without some cross-browser tweaks. Take a look at
DWREngine._unserializeDocument(). It is a private method to DWREngine,
so you should not use it directly, but you can copy it.
DWREngine._unserializeDocument = function(xml) {
? var dom;
? if (window.DOMParser) {
??? var parser = new DOMParser();
??? dom = parser.parseFromString(xml, "text/xml");
??? if (!dom.documentElement || dom.documentElement.tagName == "parsererror") {
????? var message = dom.documentElement.firstChild.data;
????? message += "\n" + dom.documentElement.firstChild.nextSibling.firstChild.data;
????? throw message;
??? }
??? return dom;
? }
? else if (
window.ActiveXObject) {
??? dom = DWREngine._newActiveXObject(DWREngine._DOMDocument);
??? dom.loadXML(xml);
??? // What happens on parse fail with IE?
??? return dom;
? }
? else {
??? var div = document.createElement
('div');
??? div.innerHTML = xml;
??? return div;
? }
};
There
is bug in IE is that I mentioned in a previous post. The bug is that
HTML nodes do not have the DOM properties to allow DWR to marshall them
properly. This might be something that DWR can work around, but to date
I have never seen the need to fix the bug. Sending the browser HTML DOM
to the server isn't all that useful since the server gave it to the
browser in the first place.
Joe.
目前的ajax框架中DWR的文檔是做的比較好的,這也有利于廣大的開發者。
DWR 官方站點:
http://getahead.ltd.uk/dwr/
DWR User-list(作者會經常對在這里提出的問題進行回答,目前已經有約5000條記錄):
http://news.gmane.org/gmane.comp.java.dwr.user
最后感謝Joe Walker,他不僅寫出了DWR,還非常熱心的回答了我和其它user的問題。
最近一直在做Web,用到ajax框架DWR,很少有地方專門討論這個東東的,希望大家能一起交流交流。
這是本人第一次加入團隊,希望能好好學習,天天向上。