|
2012年2月16日
摘要: 冒泡排序(Bubble Sort)是一種簡單的排序算法。它重復(fù)地走訪過要排序的數(shù)列,一次比較兩個元素,如果他們的順序錯誤就把他們交換過來。走訪數(shù)列的工作是重復(fù)地進行直到?jīng)]有再需要交換,也就是說該數(shù)列已經(jīng)排序完成。這個算法的名字由來是因為越小的元素會經(jīng)由交換慢慢“浮”到數(shù)列的頂端。
冒泡排序算法的運作如下:
比較相鄰的元素。如果第一個比第二個大,就交換他們... 閱讀全文
基本介紹: showModalDialog() (IE 4+ 支持) showModelessDialog() (IE 5+ 支持) window.showModalDialog() 方法用來創(chuàng)建一個顯示HTML內(nèi)容的模態(tài)對話框。 window.showModelessDialog() 方法用來創(chuàng)建一個顯示HTML內(nèi)容的非模態(tài)對話框。 使用方法: vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures]) vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures]) 參數(shù)說明: sURL -- 必選參數(shù),類型:字符串。用來指定對話框要顯示的文檔的URL。 vArguments -- 可選參數(shù),類型:變體。用來向?qū)υ捒騻鬟f參數(shù)。傳遞的參數(shù)類型不限,包括數(shù)組等。對話框通過
window.dialogArguments來取得傳遞進來的參數(shù)。 sFeatures -- 可選參數(shù),類型:字符串。用來描述對話框的外觀等信息,可以使用以下的一個或幾個,用分號“;”隔開。 ---------------- 1. dialogHeight: 對話框高度,不小于100px 2. dialogWidth: 對話框?qū)挾取?br />3. dialogLeft: 離屏幕左的距離。 4. dialogTop: 離屏幕上的距離。 5. center: { yes | no | 1 | 0 } : 是否居中,默認yes,但仍可以指定高度和寬度。 6. help: {yes | no | 1 | 0 }: 是否顯示幫助按鈕,默認yes。 7. resizable: {yes | no | 1 | 0 } [IE5+]: 是否可被改變大小。默認no。 8. status: {yes | no | 1 | 0 } [IE5+]: 是否顯示狀態(tài)欄。默認為yes[ Modeless]或no[Modal]。 9. scroll: { yes | no | 1 | 0 | on | off }:是否顯示滾動條。默認為yes。
下面幾個屬性是用在HTA中的,在一般的網(wǎng)頁中一般不使用。 10. dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印預(yù)覽時對話框是否隱藏。默認為no。 11. edge:{ sunken | raised }:指明對話框的邊框樣式。默認為raised。 12. unadorned:{ yes | no | 1 | 0 | on | off }:默認為no。
參數(shù)傳遞: 1. 要想對話框傳遞參數(shù),是通過vArguments來進行傳遞的。類型不限制,對于字符串類型,最大為4096個字符。也可以傳遞對象,例如: ------------------------------- parent.htm <script> var obj = new Object(); obj.name="51js"; window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px"); </script> modal.htm <script> var obj = window.dialogArguments alert("您傳遞的參數(shù)為:" + obj.name) </script> ------------------------------- 2.可以通過window.returnValue向打開對話框的窗口返回信息,當(dāng)然也可以是對象。例如: ------------------------------ parent.htm <script> str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px"); alert(str); </script> modal.htm <script> window.returnValue="http://homepage.yesky.com"; </script>
常見技巧:
一、怎樣才讓在showModalDialog和showModelessDialog的超連接不彈出新窗口? 在被打開的網(wǎng)頁里加上<base target="_self">就可以了。這句話一般是放在<head>之間的。
二、怎樣才刷新showModalDialog和showModelessDialog里的內(nèi)容? 在showModalDialog和showModelessDialog里是不能按F5刷新的,又不能彈出菜單。這個只能依靠
javascript了,以下是相關(guān)代碼:
<body onkeydown="if (event.keyCode==116){reload.click()}"> <a id="reload" href="filename.htm" style="display:none">reload...</a>
將filename.htm替換成網(wǎng)頁的名字然后將它放到你打開的網(wǎng)頁里,按F5就可以刷新了,注意,這個要
配合<base target="_self">使用,不然你按下F5會彈出新窗口的。
三、如何用javascript關(guān)掉showModalDialog(或showModelessDialog)打開的窗口。 <input type="button" value="關(guān)閉" onclick="window.close()"> 也要配合<base target="_self">,不然會打開一個新的IE窗口,然后再關(guān)掉的。
四、Math.random與showModalDialog。
當(dāng)你設(shè)置的彈出網(wǎng)頁固定時(如上面的"modal.htm"頁面),ie很可能到臨時文件區(qū),下載上次產(chǎn)生的該頁面(openPage.html),而沒有重新加載,
對于動態(tài)加載的頁面來說,這樣往往產(chǎn)生誤會,如沒有及時更新數(shù)據(jù),也就更不利于開發(fā)者測試。所以,你可以采用如下方式:
var strPage = “/medal.htm?random="+Math.random();
這樣每次產(chǎn)生的strPage是不一樣的,原因也就不言自明了。
下面舉兩個例子
一、返回一個字符串
首先是父頁面有個按鈕,用來打開Modal頁面userList.aspx
function openWin() { str =window.showModalDialog("userList.aspx",window,"status:0;help:0;edge:sunken;dialogWidth=700px;dialogHeight=400px");
if(str!=undefined && typeof(str)!=undefined && str!="undefined" && str!="") { document.getElementById("txtuserid").value=str; }else { document.getElementById("txtuserid").value=""; } }
str就是子頁面返回過來的數(shù)據(jù),我們把它添加到父類的一個表單元素中
子頁面
function getValue() {
var selectValue=$(":radio:checked").val(); window.returnValue=selectValue; window.close(); }
在這里我們把子頁面里的值返回到父頁面里就可以了,然后關(guān)閉頁面就可以了
二、返回一個數(shù)據(jù)
父頁面
function openWin() { array =window.showModalDialog("demo2.aspx",window,"status:0;help:0;edge:sunken;dialogWidth=700px;dialogHeight=400px;scroll:no"); document.getElementById("username").value=array[0]; document.getElementById("sex").value=array[0]; }
子頁面
function getValue() { var array=new Array(); array[0]=document.getElementById("username").value; Array[1]=document.getElementById("sex").value; window.returnValue=array; window.close(); }
返回一個數(shù)組就可以了,如果用open打開的話,在搜狗或者360瀏覽器打開的是一個頁面或者阻攔什么的
前段時間在后臺使用JS的winodw.showModalDialog來查看靜態(tài)頁面內(nèi)容,發(fā)現(xiàn)不能及時顯示更新后的頁面內(nèi)容,用open打開有時也會出現(xiàn)這種問題
解決辦法 window.showModalDialog(getUrl+"?Rnd="+Math.random(),"","dialogWidth:600px;dialogHeight:400px;help:no;scroll:yes;center:yes;status:no;"); 這樣就不會有緩存了
多思考,多創(chuàng)新,才是正道!
1.判斷select選項中 是否存在Value="paraValue"的Item $("#selectid option[@value='paraValue']").length>0 2.向select選項中 加入一個Item $("#selectid").append("<option value=''>1111<option>"); 3.從select選項中 刪除一個Item $("#selectid").remove("<option value=''>1111<option>"); 4.修改select選項中 value="paraValue"的text為"paraText" $("#selectid option:selected").attr("value","paraValue").attr("text","paraText"); 5. 設(shè)置select中text="paraText"的第一個Item為選中 $("#selectid option[@text='paraText']").attr("selected","true") 6.設(shè)置select中 value="paraValue"的Item為選中 $("#selectid option[@value='paraValue']").attr("selected","true")
7.設(shè)置select中第一 個Item為選中 $("#selectid option").eq(0).attr('selected', 'true');
8. 得到select的當(dāng)前選中項的value $("#selectid").val(); 9.得到select的當(dāng)前選中項的text $("#selectid").text(); 10. 得到select的當(dāng)前選中項的Index document.getElementById("select1").selectedIndex; $("#selectid").get(0).selectedIndex 11. 清空select的項 $("#selectid").empty();
JS版本的:
//1.判斷select選項中 是否存在Value="paraValue"的Item function jsSelectIsExitItem(objSelect,objItemValue) { var isExit = false ; for ( var i=0;i;I++) { if (objSelect.options[i].value == objItemValue) { isExit = true ; break ; } } return isExit; } //2.向select選項中 加入一個Item function jsAddItemToSelect(objSelect,objItemText,objItemValue, objItemPos) { //判斷是否存在 if (jsSelectIsExitItem(objSelect,objItemValue)) { alert( "該Item的 Value值已經(jīng)存在" ); } else { var varItem = new Option(objItemText,objItemValue); // objSelect.options[objSelect.options.length] = varItem; objSelect.options.add(varItem, objItemPos); alert( "成功加入" ); } } //3.從select選項中 刪除一個Item function jsRemoveItemFromSelect(objSelect,objItemValue) { //判斷是否存在 if (jsSelectIsExitItem(objSelect,objItemValue)) { for ( var i=0;i;I++) { if (objSelect.options[i].value == objItemValue) { objSelect.options.remove(i); break ; } } alert( "成功刪除" ); } else { alert( "該 select中 不存在該項" ); } } //4.修改select選項中 value="paraValue"的text為"paraText" function jsUpdateItemToSelect(objSelect,objItemText,objItemValue) { //判斷是否存在 if (jsSelectIsExitItem(objSelect,objItemValue)) { for ( var i=0;i;I++) { if (objSelect.options[i].value == objItemValue) { objSelect.options[i].text = objItemText; break ; } } alert( "成功修改" ); } else { alert( "該 select中 不存在該項" ); } } //5.設(shè)置select中text="paraText"的第一個 Item為選中 function jsSelectItemByValue(objSelect,objItemText) { //判斷是否存在 var isExit = false ; for ( var i=0;i;I++) { if (objSelect.options[i].text == objItemText) { objSelect.options[i].selected = true ; isExit = true ; break ; } } //Show出結(jié)果 if (isExit) { alert( "成功選中" ); } else { alert( "該 select中 不存在該項" ); } } //6.設(shè)置select中value="paraValue"的Item 為選中 document.all.objSelect.value = objItemValue; //7.得到select的當(dāng)前選中項的value var currSelectValue = document.all.objSelect.value; //8.得到select的當(dāng)前選中項的text var currSelectText = document.all.objSelect.options[document.all.objSelect.selectedIndex].text; //9.得到select的當(dāng)前選中項的Index var currSelectIndex = document.all.objSelect.selectedIndex; //10.清空select的項 document.all.objSelect.options.length = 0;
封裝 繼承 多態(tài)
面向?qū)ο蟮娜齻€基本特征是:封裝、繼承、多態(tài)。
封裝
封裝最好理解了。封裝是面向?qū)ο蟮奶卣髦唬菍ο蠛皖惛拍畹闹饕匦浴?/p>
封裝,也就是把客觀事物封裝成抽象的類,并且類可以把自己的數(shù)據(jù)和方法只讓可信的類或者對象操作,對不可信的進行信息隱藏。
繼承
面向?qū)ο缶幊?(OOP) 語言的一個主要功能就是“繼承”。繼承是指這樣一種能力:它可以使用現(xiàn)有類的所有功能,并在無需重新編寫原來的類的情況下對這些功能進行擴展。
通過繼承創(chuàng)建的新類稱為“子類”或“派生類”。
被繼承的類稱為“基類”、“父類”或“超類”。
繼承的過程,就是從一般到特殊的過程。
要實現(xiàn)繼承,可以通過“繼承”(Inheritance)和“組合”(Composition)來實現(xiàn)。
在某些 OOP 語言中,一個子類可以繼承多個基類。但是一般情況下,一個子類只能有一個基類,要實現(xiàn)多重繼承,可以通過多級繼承來實現(xiàn)。
繼承概念的實現(xiàn)方式有三類:實現(xiàn)繼承、接口繼承和可視繼承。
Ø 實現(xiàn)繼承是指使用基類的屬性和方法而無需額外編碼的能力;
Ø 接口繼承是指僅使用屬性和方法的名稱、但是子類必須提供實現(xiàn)的能力;
Ø 可視繼承是指子窗體(類)使用基窗體(類)的外觀和實現(xiàn)代碼的能力。
在考慮使用繼承時,有一點需要注意,那就是兩個類之間的關(guān)系應(yīng)該是“屬于”關(guān)系。例如,Employee 是一個人,Manager 也是一個人,因此這兩個類都可以繼承 Person 類。但是 Leg 類卻不能繼承 Person 類,因為腿并不是一個人。
抽象類僅定義將由子類創(chuàng)建的一般屬性和方法,創(chuàng)建抽象類時,請使用關(guān)鍵字 Interface 而不是 Class。
OO開發(fā)范式大致為:劃分對象→抽象類→將類組織成為層次化結(jié)構(gòu)(繼承和合成) →用類與實例進行設(shè)計和實現(xiàn)幾個階段。
多態(tài)
多態(tài)性(polymorphisn)是允許你將父對象設(shè)置成為和一個或更多的他的子對象相等的技術(shù),賦值之后,父對象就可以根據(jù)當(dāng)前賦值給它的子對象的特性以不同的方式運作。簡單的說,就是一句話:允許將子類類型的指針賦值給父類類型的指針。
實現(xiàn)多態(tài),有二種方式,覆蓋,重載。
覆蓋,是指子類重新定義父類的虛函數(shù)的做法。
重載,是指允許存在多個同名函數(shù),而這些函數(shù)的參數(shù)表不同(或許參數(shù)個數(shù)不同,或許參數(shù)類型不同,或許兩者都不同)。
其實,重載的概念并不屬于“面向?qū)ο缶幊?#8221;,重載的實現(xiàn)是:編譯器根據(jù)函數(shù)不同的參數(shù)表,對同名函數(shù)的名稱做修飾,然后這些同名函數(shù)就成了不同的函數(shù)(至少對于編譯器來說是這樣的)。如,有兩個同名函數(shù):function func(p:integer):integer;和function func(p:string):integer;。那么編譯器做過修飾后的函數(shù)名稱可能是這樣的:int_func、str_func。對于這兩個函數(shù)的調(diào)用,在編譯器間就已經(jīng)確定了,是靜態(tài)的(記住:是靜態(tài))。也就是說,它們的地址在編譯期就綁定了(早綁定),因此,重載和多態(tài)無關(guān)!真正和多態(tài)相關(guān)的是 “覆蓋”。當(dāng)子類重新定義了父類的虛函數(shù)后,父類指針根據(jù)賦給它的不同的子類指針,動態(tài)(記住:是動態(tài)!)的調(diào)用屬于子類的該函數(shù),這樣的函數(shù)調(diào)用在編譯期間是無法確定的(調(diào)用的子類的虛函數(shù)的地址無法給出)。因此,這樣的函數(shù)地址是在運行期綁定的(晚邦定)。結(jié)論就是:重載只是一種語言特性,與多態(tài)無關(guān),與面向?qū)ο笠矡o關(guān)!引用一句Bruce Eckel的話:“不要犯傻,如果它不是晚邦定,它就不是多態(tài)。”
那么,多態(tài)的作用是什么呢?我們知道,封裝可以隱藏實現(xiàn)細節(jié),使得代碼模塊化;繼承可以擴展已存在的代碼模塊(類);它們的目的都是為了——代碼重用。而多態(tài)則是為了實現(xiàn)另一個目的——接口重用!多態(tài)的作用,就是為了類在繼承和派生的時候,保證使用“家譜”中任一類的實例的某一屬性時的正確調(diào)用。
泛化(Generalization)
在上圖中,空心的三角表示繼承關(guān)系(類繼承),在UML的術(shù)語中,這種關(guān)系被稱為泛化(Generalization)。Person(人)是基類,Teacher(教師)、Student(學(xué)生)、Guest(來賓)是子類。
若在邏輯上B是A的“一種”,并且A的所有功能和屬性對B而言都有意義,則允許B繼承A的功能和屬性。
例如,教師是人,Teacher 是Person的“一種”(a kind of )。那么類Teacher可以從類Person派生(繼承)。
如果A是基類,B是A的派生類,那么B將繼承A的數(shù)據(jù)和函數(shù)。
如果類A和類B毫不相關(guān),不可以為了使B的功能更多些而讓B繼承A的功能和屬性。
若在邏輯上B是A的“一種”(a kind of ),則允許B繼承A的功能和屬性。
聚合(組合)
若在邏輯上A是B的“一部分”(a part of),則不允許B從A派生,而是要用A和其它東西組合出B。
例如,眼(Eye)、鼻(Nose)、口(Mouth)、耳(Ear)是頭(Head)的一部分,所以類Head應(yīng)該由類Eye、Nose、Mouth、Ear組合而成,不是派生(繼承)而成。
聚合的類型分為無、共享(聚合)、復(fù)合(組合)三類。
聚合(aggregation)
上面圖中,有一個菱形(空心)表示聚合(aggregation)(聚合類型為共享),聚合的意義表示has-a關(guān)系。聚合是一種相對松散的關(guān)系,聚合類B不需要對被聚合的類A負責(zé)。
組合(composition)
這幅圖與上面的唯一區(qū)別是菱形為實心的,它代表了一種更為堅固的關(guān)系——組合(composition)(聚合類型為復(fù)合)。組合表示的關(guān)系也是has-a,不過在這里,A的生命期受B控制。即A會隨著B的創(chuàng)建而創(chuàng)建,隨B的消亡而消亡。
依賴(Dependency)
這里B與A的關(guān)系只是一種依賴(Dependency)關(guān)系,這種關(guān)系表明,如果類A被修改,那么類B會受到影響
數(shù)列6,10,18,32,“?”,問“?”是幾?
1。什么是3G,2。3C 融合技術(shù),3。對大唐的認識。 3G有三大制式,GSM升級后的WCDMA,CDMA升級后的CDMA2000,以及我國自主開發(fā)的TD-SCDMA。 第三代移動通信技術(shù)(3rd-generation,3G),是指支持高速數(shù)據(jù)傳輸?shù)姆涓C移動通訊技術(shù)。3G服務(wù)能夠同時傳送聲音及數(shù)據(jù)信息,速率一般在幾百kbps以上。目前3G存在四種標(biāo)準(zhǔn):CDMA2000,WCDMA,TD-SCDMA,WiMAX。 所謂“3C產(chǎn)品”,就是計算機(Computer)、通信(Communication)和消費類電子產(chǎn)品(ConsumerElectronics)三者結(jié)合,亦稱“信息家電”。由于3C產(chǎn)品的體積一般都不大,所以往往在中間加一個“小”字,故往往統(tǒng)稱為“3C小家電”。 3C指的是計算機(Computer)、通訊(Communication)和消費類電子產(chǎn)品(Consumer Electrics)。3C融合即利用數(shù)字信息技術(shù)激活其中任何一個環(huán)節(jié),通過某種協(xié)議使3C的三個方面實現(xiàn)信息資源的共享和互聯(lián)互通,從而滿足人們在任何時間、任何地點通過信息關(guān)聯(lián)應(yīng)用來方便自己的生活。 無線寬帶正是實現(xiàn)數(shù)字家庭3C融合的首要步驟。
第一部分:選擇題 1.相同碼元速率下,那種傳輸方式信息傳輸速率最高 QPSK 16QAM BPSK GMSK 2.下面哪些屬于差錯控制編碼 3.自由空間傳播環(huán)境下信號衰減與距離( )次方成比例 4.下列哪些功能屬于網(wǎng)絡(luò)管理的功能域5a880faf6f?應(yīng)屆生求職網(wǎng)YingJieSheng.COM?c350ade2a4 故障管理配置管理計費管理性能管理安全管理傳輸管理路由管理 5.采用CDMA技術(shù)通信系統(tǒng),擾碼的主要作用 信道估計信道區(qū)分信號白化同步 6.交織的主要作用 7.數(shù)據(jù)鏈路層的協(xié)議是 HDLC ARQ PPP ICMP RTP6fe97759aa?應(yīng)屆生求職網(wǎng)YingJieSheng.COM?b922cfa312 8.那種ATM協(xié)議最適合應(yīng)用話音業(yè)務(wù) AAL5 AAL4 AAL3 AAL2 第二部分:填空問答 1.香農(nóng)公式表達式 2.愛爾蘭含義 最大話務(wù)量和BHCA分別取決于什么5568161a8c?應(yīng)屆生求職網(wǎng)YingJieSheng.COM?d5792c152c 3.中繼器,網(wǎng)橋.路由器,網(wǎng)關(guān)各是兩個網(wǎng)絡(luò)的哪層連接;路由器的功能是( )和( ) 4.解釋QPSK調(diào)制的原理 5.簡述dB,dBm的概念 6.畫出數(shù)字通信系統(tǒng)的模型,簡述信源編碼和信道編碼的區(qū)別,及其它們在無線通信系統(tǒng)中的作用 7.C語言中能否在頭文件中定義變量,并說明原因 8.在Windows系統(tǒng),能否動態(tài)鏈接庫中定義變量,如果可以定義說明有效范圍4005f8da13?應(yīng)屆生求職網(wǎng)YingJieSheng.COM?60d149af1f 9.結(jié)構(gòu)化程序設(shè)計中程序= 面向?qū)ο蟪绦蛟O(shè)計中程序= 10.解釋return和exit的區(qū)別 11.ATM網(wǎng)絡(luò)信元長度是( ),所有信息在最底層以( )的方式傳送,以保持電路交換適合于傳送實時性很強的業(yè)務(wù)特點. 12.什么是TDD,什么是FDD,多址方式又指什么?列出你所了解的多址方式 13.談?wù)剬SI或計算機網(wǎng)絡(luò)中”協(xié)議””實體””服務(wù)”的理解以及什么是SDU PDU和Primitive?8f07f89ddb?應(yīng)屆生求職網(wǎng)YingJieSheng.COM?4c20a920bf 14.GSM邏輯信道及分類 15.談?wù)勀銓σ苿油ㄐ畔到y(tǒng)組成的理解.
1. 描述一下public,protected,private,final關(guān)鍵字在Java中的用法? public表示公共的,定義類的時候工程下任何包都可以讀取到,protected是受保護的,只有在相同包內(nèi)的類才能讀取到,private定義方法時候只能在類內(nèi)部才能讀取到。final表示一個終態(tài),是不可改變的。 2. Abstract class 和Interface 有什么區(qū)別? 抽象類和接口的區(qū)別如下: (1、)抽象類是類,接口是接口; (2、)抽象類只能繼承一個,接口可以多實現(xiàn); (3、)抽象類定義一些靜態(tài)變量可以,接口中不行; 3. Vector 和 ArrayList 有什么區(qū)別? HashTable 和 HashMap有什么區(qū)別? vector 和 Arraylist都是繼承自集合類collection,vector是鏈表的方式實現(xiàn)的,讀取熟讀快,添加數(shù)據(jù)時候慢,Arraylist里面添加數(shù)據(jù)慢讀取數(shù)據(jù)快。 Hashtable和HashMap最大的區(qū)別是HashTable是同步的,HashMap是非同步的,所以性能上相對快一點,HashTable是繼承自Dictionary類,而HashMap是繼承自Map接口 4. Java集合中的Iterator起什么作用? java集合中Iterator主要作用是去除重復(fù); 5. Java中創(chuàng)建一個對象有哪幾種方法,區(qū)別是什么? java中創(chuàng)建對象可以實例化new 6. 多線程有幾種表示方法,都是什么?同步有幾種實現(xiàn)方法,都是什么? 多線程可以通過實現(xiàn)runable接口,也可以繼承Thread類來實現(xiàn)。 實現(xiàn)同步也有兩種,一種是用同步方法,一種是用同步塊.. 同步方法就是在方法返回類型后面加上synchronized, 比如: public void synchronized add(){...} 同步塊就是直接寫:synchronized (這里寫需要同步的對象){...} wait():使一個線程處于等待狀態(tài),并且釋放所持有的對象的lock。 sleep():使一個正在運行的線程處于睡眠狀態(tài),是一個靜態(tài)方法,調(diào)用此方法要捕捉InterruptedException異常。 notify():喚醒一個處于等待狀態(tài)的線程,注意的是在調(diào)用此方法的時候,并不能確切的喚醒某一個等待狀態(tài)的線程,而是由JVM確定喚醒哪個線程,而且不是按優(yōu)先級。 Allnotity():喚醒所有處入等待狀態(tài)的線程,注意并不是給所有喚醒線程一個對象的鎖,而是讓它們競爭。 7. 描述一下Java中的異常機制,什么是Checked Exception, Unchecked Exception? java中的異常機制要求你對一些存在的問題進行實現(xiàn)的規(guī)劃,并對相應(yīng)的Exception的情況進行設(shè)定,當(dāng)程序捕獲類似的情況就會拋出異常,你可以定義異常的處理方法,異常并不是致命的,它與錯誤有著區(qū)別,錯誤只要發(fā)生程序就會終止,但是異常會繼續(xù)執(zhí)行下去。 java中的異常包括受檢查的異常和不受檢查的異常,(1、)受檢查的異常:這種在編譯時候被強制檢查的異常被稱作受檢查異常,即在方法中聲明的異常。(2、)不受檢查的異常:在方法得聲明中沒有聲明,但在方法的運行過程中發(fā)生的各種異常叫做不受檢查的異常,這種異常是錯誤,會被自動捕獲。一些規(guī)模較小的程序中,受檢查的異常能夠提高開發(fā)效率,但隨著項目規(guī)模的擴大,過的的受檢查的異常變得難以管理,其帶來的好處也消失殆盡。 8. 描述一下Java ClassLoader 或者 J2EE ClassLoader的工作原理?(可以畫圖) 當(dāng)運行程序是首先運行java虛擬機(JVM),然后把java class加載到JVM里運行,負責(zé)加載java class的這部分就叫做java ClsssLoader, JVM本身包含一個ClassLoader成為bootstrap ClassLoader,和JVM一樣,BootstrapClassLoader使用本地代碼實現(xiàn)的,它負責(zé)加載核心javaClass(即所有java.*開頭的類)。另外JVM還提供兩個ClassLoader,他們都是用java語言實現(xiàn)的,都是由BootstrapClassLoader負責(zé)加載,其中Extention ClassLoader負責(zé)加載擴展的javaclass(例如所有以javax.*開頭的類和存放在JRE的ext目錄下的類),ApplicationClassLoader負責(zé)加載應(yīng)用程序自身的類。 當(dāng)運行一個程序的時候,JVM啟動,運行Bootstrapclassloader,該classloader加載核心API(ExtClassloader和AppClassloader也在此時被加載),然后調(diào)用Extclassloader加載擴展API,最后AppClassloader加載CLASSPATH目錄下定義的Class,這就是一個程序最基本的加載流程。
9. MVC的各個部分都有那些技術(shù)來實現(xiàn)?如何實現(xiàn)? MVC主要包括模型層,視圖層,控制層。 模型層主要由javabean實現(xiàn),視圖層是由jsp實現(xiàn),控制層主要由servlet實現(xiàn)。 10. 描述一下Struts的工作方式? struts1.2的工作方式主要是MVC實現(xiàn),struts2是攔截器的方式實現(xiàn)。 11. JSP中包含哪幾個內(nèi)置對象? jsp包括九個內(nèi)置對象,分別為:request,response,session,cookie,out,application,pageRequest,Exception, 12. JSP中兩種跳轉(zhuǎn)方式分別是什么?有什么區(qū)別? jsp兩種跳轉(zhuǎn)方式是重定向和頁面跳轉(zhuǎn),其中重定向方式執(zhí)行,form表單提交數(shù)據(jù)會失去,網(wǎng)絡(luò)地址會變化,頁面跳轉(zhuǎn)不會; 13. 描述一下JSP中taglib的用法? jsp中標(biāo)簽可以使java代碼嵌入到頁面上使用 14. Javascript中如何校驗數(shù)字型? 正則表達式 15. EJB2.0中包括哪些內(nèi)容? 作用分別是什么? EJB2.0 16. 一個SessionBean包含哪幾個組件?各個組件作用是什么? 17. 描述一下一個EJB應(yīng)用中EJB部署文件,以及你所熟悉的App Server的部署文件的作用? 18. 列舉一下你所知道的設(shè)計模式(包括EJB,J2EE的設(shè)計模式),以及他們應(yīng)用的場合? 代理模式:把一個對象注入到一個類中通過這個注入的對象來完成一系列方法, 工廠模式:一個接口下的所有類的實例可以通過專門的工廠類通過傳遞不同的參數(shù)來實現(xiàn); Adapter(適配器)模式:將一個類的接口轉(zhuǎn)換成客戶希望的另外一個接口。Adapter模式使得原本由于接口不兼容而不能一起工作的那些類可以一起工作。適配器模式的用意是將接口不同而功能相同或者相近的兩個接口加以轉(zhuǎn)換。 單例模式:單例模式有兩種: 餓漢模式 public class Singleton { private Singleton(); priavate static Singleton singleton = new Singleton(); public staic Singleton getInstance() { return instance; } } 懶漢模式: public class Singleton { private static Singleton singleton = new Singleton(); public static synchronize Singleton() { if(instance == null) { instance = new singleton(); } return instance; } } 19. 解析XML主要方法有哪些? 各有什么區(qū)別? 1、xml有哪些解析技術(shù)?區(qū)別是什么?
2、你在項目中用到了xml技術(shù)的哪些方面?如何實現(xiàn)的?
3、用jdom解析xml文件時如何解決中文問題?如何解析?
4、編程用JAVA解析XML的方式.
1、xml有哪些解析技術(shù)?區(qū)別是什么? 解析XMl方法主要方法有文件流讀取,頁面XMLHttp讀取。 DOM:處理大型文件時其性能下降的非常厲害。這個問題是由DOM的樹結(jié)構(gòu)所造成的,這種結(jié)構(gòu)占用的內(nèi)存較多,而且dom必須在解析文件之前把整個文檔裝入內(nèi)存 SAX:適合對XML文件的隨機訪問,不像DOM,SAX是事件驅(qū)動型的XML解析方式。它順序讀取XML文件,不需要一次全部裝載整個文件。 StAX:當(dāng)遇到像文件開頭,文檔結(jié)束,或者標(biāo)簽開頭與標(biāo)簽結(jié)束時,它會觸發(fā)一個事件,用戶通過在其回調(diào)事件中寫入處理代碼來處理XML文件,適合對XML的順序訪問STAX:Streaming API for XML (StAX) 2、主要用到了信息存儲信息配置兩方面,在做數(shù)據(jù)交換平臺時,將不能用數(shù)據(jù)源的數(shù)據(jù)組裝成xml文件,然后將xml文件壓縮打包加密后發(fā)給接收者,接受解密解壓縮后再同xml文件中還原相關(guān)信息進行處理。在做軟件配置時候,利用xml文件可以方便的進行,軟件的各種配置都存儲在xml文件中。 3、 20. 您了解Open Source的項目嗎? 如果了解請描述幾個,并講述一下他們的作用? apchetomcat就是一個比較好的開源項目,主要作為服務(wù)器來使用。 struts是一個主要用于作為控制層的開源框架項目, spring是一個輕量級的開源項目,通過控制反轉(zhuǎn)和代理模式實現(xiàn) Hibernate是個持久層框架,用來建立與數(shù)據(jù)庫的持久層 21. 您看過哪些JAVA方面的書籍,能列舉一下嗎? think in java ,core java,jquery in action, struts,spring ,hibernate等等方面的書都有涉獵。
<%@ page pageEncoding="utf-8" %>
<%@ page language="java" contentType="text/html; charset=GBK" %><%@ page import="java.util.*" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="jxl.Workbook" %>
<%@ page import="jxl.write.WritableCellFormat" %>
<%@ page import="jxl.write.WritableSheet" %>
<%@ page import="jxl.write.WritableWorkbook" %>
<%@ page import="jxl.write.WriteException" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "filename=Member.xls");//attachment// WritableWorkbook是JexcelApi的一個類。
// 以下可以理解為創(chuàng)建一個excel文件,然后在excel里面創(chuàng)建一個表
OutputStream os = response.getOutputStream();//取得輸出流
WritableWorkbook workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("First Sheet", 0);// 組織excel文件的內(nèi)容
jxl.write.Label label = null;
int excelCol = 0;
int row = 0;
try {
label = new jxl.write.Label(excelCol++, row, "帳號");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "姓名");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "身份證");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "聯(lián)系電話");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "生日");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "城市");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "職業(yè)");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "已購音箱型號");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "試聽與否");
sheet.addCell(label);
label = new jxl.write.Label(excelCol++, row, "郵箱");
sheet.addCell(label);
label = new jxl.write.Label(excelCol, row, "注冊時間");
sheet.addCell(label);
//jxl.write.Number number = null;
jxl.write.DateTime dateTime;
jxl.write.DateFormat customDateFormat = new jxl.write.DateFormat("yyyy-MM-dd");//時間格式
WritableCellFormat dateFormat = new WritableCellFormat(customDateFormat); for(int i=0;i<10;i++){
excelCol = 0;
row = i + 1; SimpleDateFormat formatDate = new SimpleDateFormat("yyyy-MM-dd");
sheet.addCell(label); label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); /*字串格式*/
try{
label = new jxl.write.Label(excelCol++, row, formatDate.format("100"));
sheet.addCell(label);
}catch (Exception e){
//Maybe somebody fogot to input his birthday ,I need do nothing here!
} label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); label = new jxl.write.Label(excelCol++, row, "100");
sheet.addCell(label); /*時間格式*/
//label = new jxl.write.Label(excelCol, row, formatDate.format(rr.getCreateTime()));
//sheet.addCell(label);
}
} catch (Exception e) {
e.printStackTrace();
} finally{
// 生成excel文件
workbook.write();
workbook.close();
os.close();
}
%>
網(wǎng)上的 Jquery ajax Demo 大多都是基于php 很少 有java的 今天就把自己的Demo貼出來 和大家共同學(xué)習(xí) 現(xiàn)在就 Jquery ajax 的 $.ajax(),$.post(),$.get();
首先是 服務(wù)端的Servlet 演示這三個函數(shù)的用法對都是用的同一個 服務(wù)端 Java代碼 package com.june.servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; public class jqueryAjaxServer extends HttpServlet { public jqueryAjaxServer(){ super(); } public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException ,ServletException { response.setContentType("text/html;charset=utf-8"); PrintWriter out=response.getWriter(); String account=request.getParameter("account"); if("iamcrzay".equals(account)){ out.print("Sorry,the user is exist"); } else{ out.print("Congratulation,this accont you can use!!!!"); } out.close(); } public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException ,ServletException { this.doGet(request, response); } }
package com.june.servlet;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException;
public class jqueryAjaxServer extends HttpServlet { public jqueryAjaxServer(){ super(); } public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException ,ServletException { response.setContentType("text/html;charset=utf-8"); PrintWriter out=response.getWriter(); String account=request.getParameter("account"); if("iamcrzay".equals(account)){ out.print("Sorry,the user is exist"); } else{ out.print("Congratulation,this accont you can use!!!!"); } out.close(); } public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException ,ServletException { this.doGet(request, response); } }
下面是WEB.XML Xml代碼 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns=" xmlns:xsi=" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <servlet> <servlet-name>jqueryAjaxServer</servlet-name> <servlet-class>com.june.servlet.jqueryAjaxServer</servlet-class> </servlet> <servlet-mapping> <servlet-name>jqueryAjaxServer</servlet-name> <url-pattern>/jqueryAjax</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns=" xmlns:xsi=" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <servlet> <servlet-name>jqueryAjaxServer</servlet-name> <servlet-class>com.june.servlet.jqueryAjaxServer</servlet-class> </servlet> <servlet-mapping> <servlet-name>jqueryAjaxServer</servlet-name> <url-pattern>/jqueryAjax</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
下面是Jsp頁面 第一個是 jqueryAjax.jsp 本頁使用的是$.ajax() Html代碼 <%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click(function(){ if($('#account').val().length==0){ $('.hint').text("用戶名不能位空").css({"background-color":"green"}); } else{ $.ajax({ url:'jqueryAjax', data:{account:$('#account').val()}, error:function(){ alert("error occured!!!"); }, success:function(data){ $('body').append("<div>"+data+"</div>").css("color","red"); } });} }); }); </script> </head> <body> <h3 align="center">jquery AjaX</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html>
<%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click(function(){ if($('#account').val().length==0){ $('.hint').text("用戶名不能位空").css({"background-color":"green"}); } else{ $.ajax({ url:'jqueryAjax', data:{account:$('#account').val()}, error:function(){ alert("error occured!!!"); }, success:function(data){ $('body').append("<div>"+data+"</div>").css("color","red"); } });} }); }); </script> </head> <body> <h3 align="center">jquery AjaX</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html>
第二個用的是 $.post()
Html代碼 <%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click( function(){ if($('#account').val().length==0){ $('.hint').text("The account is cant't be null").css({"color":"red","background-color":"yellow"}); } else{ $.post("jqueryAjax","account="+$('#account').val(),function(data){ $('.hint').text(data).css({"color":"red","background-color":"yellow"}); }) } }); }); </script> </head> <body> <h3 align="center">jquery Ajax</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html>
<%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click( function(){ if($('#account').val().length==0){ $('.hint').text("The account is cant't be null").css({"color":"red","background-color":"yellow"}); } else{ $.post("jqueryAjax","account="+$('#account').val(),function(data){ $('.hint').text(data).css({"color":"red","background-color":"yellow"}); }) } }); }); </script> </head> <body> <h3 align="center">jquery Ajax</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html>
第三個是用的$.get()
Html代碼 <%@ page pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery get</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('.sumbit').click(function(){ if($('#account').val().length==0){ $('.hint').html("用戶名不能位空!!!").css({"color":"#ffoo11","background":"blue"}); } else{ $.get("jqueryAjax","account="+$('#account').val(), function(data){ $('.hint').html(data).css({"color":"#ffoo11","background":"green"}); }); } }); }); </script> </head> <body> <h3 align="center">jquery AjaX</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html>
div#loadPic { width: 10%; height:40px; position:absolute; z-index:4; margin-top: 50px; margin-bottom: 50px; margin-left: auto; margin-right: auto; padding: 0px; top:30%; }
url=jsp?str="你好!" String areaName=(String)request.getParameter("areaname"); String dpt=new String(dptName.getBytes("ISO8859-1"),"UTF-8");
apache-comcat配置虛擬主機和虛擬目錄 jquery autocomplete 自動填充文本框、文本域 JS 導(dǎo)出excel,word實例 2011-10-10 11:55:00| 分類: 默認分類 | 標(biāo)簽:js excel word |字號大 中 小 訂閱 用js操作offace中的word,excel 必須首先確保你已經(jīng)安裝office,用js操作word,excel 用到了ActiveXObject類,它是專門用來調(diào)用windows操作中的程序的,下面是例子,直接復(fù)制到文本文件里,把后綴名改了就可以運行!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>無標(biāo)題文檔</title> <script type="text/javascript" language="javascript"> function ExcelExport(tableid) {
//檢索瀏覽器 if(navigator.userAgent.indexOf("MSIE")<0){ alert('請用ie瀏覽器進行表格導(dǎo)出'); return ; } var oXL = null; try { oXL = GetObject("", "Excel.Application"); } catch (E) { try { oXL = new ActiveXObject("Excel.Application"); } catch (E2) { alert("請確認:\n1.Microsoft Excel已被安裝.\n2.工具 => Internet 選項=> 安全 => 設(shè)置 \"啟用不安全的 ActiveX\""); return; } }
var table = document.getElementById(tableid); var workbook = oXL.Workbooks.Add(); var sheet = workbook.ActiveSheet; var sel = document.body.createTextRange(); //激活sheet //把table中的數(shù)據(jù)移到sel中 sel.moveToElementText(table); sel.select(); //選中sel中所有數(shù)據(jù) sel.execCommand("Copy");//復(fù)制sel中的數(shù)據(jù) sheet.Columns("A:Z").ColumnWidth =20;//設(shè)置列寬 // sheet.Columns("B").ColumnWidth =35; sheet.Rows(1).RowHeight = 35;//設(shè)置表頭高 //將sel中數(shù)據(jù)拷貝到sheet工作薄中 sheet.Paste(); oXL.Visible = true; //sheet.Save("F:\\TEST.XLS" ); //通過打印機直接將Excel數(shù)據(jù)打印出來 //sheet.Printout; //ax.UserControl = true; oXL.Quit(); oXL=null; } </script> </head>
<body> <table width="100%" border="1" id="mytable"> <tr> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> </tr> <tr> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> </tr> <tr> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> </tr> <tr> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> </tr> <tr> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> <td>nihao</td> </tr> </table> <form id="form1" name="form1" method="post" action=""> <label> <input type="button" name="Submit" value="導(dǎo)出excel" onclick="ExcelExport('mytable')" /> </label> </form> <p> </p> </body> </html>
http://www.wujianrong.com/archives/2007/05/20jspajax.html 簡單用例 http://www.ibm.com/developerworks/cn/web/wa-ajaxintro/ IBM—Ajax講解 http://www.w3schools.com/ajax/ajax_example.asp Ajax—Example W3CSchol <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "> <html> <head> <script src="ajax. js"></script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page using AJAX</title> </head> <body> <a onclick="sendRequest('GET','index.jsp')" href="#">Server Date Time:</a> <div id="ajax_res">Server Date Time will replace this text.</div> </body> </html> index.jsp <html> <body> <%=new java.util.Date()%> </body> </html> ajax. jsfunction createRequestObject(){ var req; if(window.XMLHttpRequest){ //For Firefox, Safari, Opera req = new XMLHttpRequest(); } else if(window.ActiveXObject){ //For IE 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else{ //Error for an old browser alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera'); } return req; } //Make the XMLHttpRequest Object var http = createRequestObject(); function sendRequest(method, url){ if(method == 'get' || method == 'GET'){ http.open(method,url); http.onreadystatechange = handleResponse; http.send(null); } } function handleResponse(){ if(http.readyState == 4 && http.status == 200){ var response = http.responseText; if(response){ document.getElementById("ajax_res").innerHTML = response; } } } run this application may be u get some clue
假設(shè):
1、你的頁面在Web-Root下,內(nèi)容為: <div id="showMsg"></div><input type="text" id="userName" />,所用編碼為utf-8
2、你的servlet為: HelloWorldServlet.java 映射路徑為 servlet/helloWorldServlet
步驟:
1、引入jquery-1.6.4.min.js
2、編寫id為userName的輸入框的點擊觸發(fā)函數(shù):
$("#userName").keyup(function(){
$.ajax({
type: "post",
url: "servlet/helloWorldServlet?userName="+$(this).val(),
dataType: "json",
success: function(data){
$("#showMsg").html(data.msg);//修改id為showMsg標(biāo)簽的html
}, error: function(){
alert("請求出錯");
}
})
})
3、后臺處理接收到的內(nèi)容:
request.setCharactorEncoding("utf-8");
String userName = request.getParameter("userName");
response.setCharactorEncoding("utf-8");
PringWriter out = response.getWriter();
out.print("{\"msg\":\"你好~~"+userName+"!\"}");
注意事項:
1、這里的編碼統(tǒng)一為utf-8
2、請求路徑servlet/helloWorldServlet為相對路徑,因此你的頁面必須在項目的Web-Root下(也就是默認的web文件夾下,名字可能因項目配置不同而改變)
網(wǎng)上的 Jquery ajax Demo 大多都是基于php 很少 有java的 今天就把自己的Demo貼出來 和大家共同學(xué)習(xí) 現(xiàn)在就 Jquery ajax 的 $.ajax(),$.post(),$.get();
首先是 服務(wù)端的Servlet 演示這三個函數(shù)的用法對都是用的同一個 服務(wù)端
package com.june.servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; public class jqueryAjaxServer extends HttpServlet { public jqueryAjaxServer(){ super(); } public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException ,ServletException { response.setContentType("text/html;charset=utf-8"); PrintWriter out=response.getWriter(); String account=request.getParameter("account"); if("iamcrzay".equals(account)){ out.print("Sorry,the user is exist"); } else{ out.print("Congratulation,this accont you can use!!!!"); } out.close(); } public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException ,ServletException { this.doGet(request, response); } }
下面是WEB.XML Xml代碼 <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns=" xmlns:xsi=" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <servlet> <servlet-name>jqueryAjaxServer</servlet-name> <servlet-class>com.june.servlet.jqueryAjaxServer</servlet-class> </servlet> <servlet-mapping> <servlet-name>jqueryAjaxServer</servlet-name> <url-pattern>/jqueryAjax</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns=" xmlns:xsi=" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <servlet> <servlet-name>jqueryAjaxServer</servlet-name> <servlet-class>com.june.servlet.jqueryAjaxServer</servlet-class> </servlet> <servlet-mapping> <servlet-name>jqueryAjaxServer</servlet-name> <url-pattern>/jqueryAjax</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> 下面是Jsp頁面 第一個是 jqueryAjax.jsp 本頁使用的是$.ajax() Html代碼 <%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click(function(){ if($('#account').val().length==0){ $('.hint').text("用戶名不能位空").css({"background-color":"green"}); } else{ $.ajax({ url:'jqueryAjax', data:{account:$('#account').val()}, error:function(){ alert("error occured!!!"); }, success:function(data){ $('body').append("<div>"+data+"</div>").css("color","red"); } });} }); }); </script> </head> <body> <h3 align="center">jquery AjaX</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html> <%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click(function(){ if($('#account').val().length==0){ $('.hint').text("用戶名不能位空").css({"background-color":"green"}); } else{ $.ajax({ url:'jqueryAjax', data:{account:$('#account').val()}, error:function(){ alert("error occured!!!"); }, success:function(data){ $('body').append("<div>"+data+"</div>").css("color","red"); } });} }); }); </script> </head> <body> <h3 align="center">jquery AjaX</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html> 第二個用的是 $.post() Html代碼 <%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click( function(){ if($('#account').val().length==0){ $('.hint').text("The account is cant't be null").css({"color":"red","background-color":"yellow"}); } else{ $.post("jqueryAjax","account="+$('#account').val(),function(data){ $('.hint').text(data).css({"color":"red","background-color":"yellow"}); }) } }); }); </script> </head> <body> <h3 align="center">jquery Ajax</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html> <%@ page language="java" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery ajax</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script language="javascript"> $(function(){ $('.sumbit').click( function(){ if($('#account').val().length==0){ $('.hint').text("The account is cant't be null").css({"color":"red","background-color":"yellow"}); } else{ $.post("jqueryAjax","account="+$('#account').val(),function(data){ $('.hint').text(data).css({"color":"red","background-color":"yellow"}); }) } }); }); </script> </head> <body> <h3 align="center">jquery Ajax</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html> 第三個是用的$.get() Html代碼 <%@ page pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery get</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('.sumbit').click(function(){ if($('#account').val().length==0){ $('.hint').html("用戶名不能位空!!!").css({"color":"#ffoo11","background":"blue"}); } else{ $.get("jqueryAjax","account="+$('#account').val(), function(data){ $('.hint').html(data).css({"color":"#ffoo11","background":"green"}); }); } }); }); </script> </head> <body> <h3 align="center">jquery AjaX</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html> <%@ page pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>jquery get</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script src="js/jquery-1.2.6.js" type="text/javascript"></script> <script type="text/javascript"> $(function(){ $('.sumbit').click(function(){ if($('#account').val().length==0){ $('.hint').html("用戶名不能位空!!!").css({"color":"#ffoo11","background":"blue"}); } else{ $.get("jqueryAjax","account="+$('#account').val(), function(data){ $('.hint').html(data).css({"color":"#ffoo11","background":"green"}); }); } }); }); </script> </head> <body> <h3 align="center">jquery AjaX</h3> <hr> <label>請輸入用戶名 :</label> <input id="account" name="account" type="text"> <input class="sumbit" type="button" value="檢測"> <div class="hint"> </div> </body> </html>
http://iamcrzay.iteye.com/blog/237940
1、將數(shù)組轉(zhuǎn)化成字符串,用特殊字符如“|”將數(shù)組的元素隔開,用普通的字符串參數(shù)傳遞
2、使用json方式傳遞參數(shù)
解析
C#后臺得到的是個string string objStr = HttpContext.Current.Request["objStr"];
objStr內(nèi)容([{"0": "a", "1": "b", "2": "c", "3": "d"}, {"0": "aa", "1": "bb", "2": "cc", "3": "dd"}{"0": "aa", "1": "bb"}])
/// <summary> /// 從JS數(shù)組中解析出JSON對象返回該對象的字符串表示 /// </summary> /// <param name="ArrayStr"></param> /// <returns></returns> private static string GetJsonStr(string ArrayStr) { //ArrayStr="[{'0': 'a', '1': 'b', '2': 'c', '3': 'd'},{'0': 'aa', '1': 'bb', '2': 'cc', '3': 'dd'},{'0': 'aa', '1': 'bb'}]"; string StrJson = ArrayStr;
//將"[{"和"}]"去除; //StrJson="'0': 'a', '1': 'b', '2': 'c', '3': 'd'},{'0': 'aa', '1': 'bb', '2': 'cc', '3': 'dd'},{'0': 'aa', '1': 'bb'"; StrJson = StrJson.Substring(2, StrJson.Length - 4);
//將“},{”替換為“|”便于分割成數(shù)組 //StrJson="'0': 'a', '1': 'b', '2': 'c', '3': 'd'|'0': 'aa', '1': 'bb', '2': 'cc', '3': 'dd'|'0': 'aa', '1': 'bb'"; StrJson = StrJson.Replace("},{", "|"); //以“|”為分隔符將每個JSON對象分割成字符串 /*結(jié)果為:strjson[0]="'0': 'a', '1': 'b', '2': 'c', '3': 'd'"; strjson[1]="'0': 'aa', '1': 'bb', '2': 'cc', '3': 'dd'"; strjson[2]="'0': 'aa', '1': 'bb'";*/ return StrJson.Split('|'); }
ask.jsp
<script language="javascript" type="text/javascript"> function Open() {
window.open('<%=path%>/jsp/answer.jsp' ,'_blank','top=250,left=300,width=500 height=100'); } </script>
<body> <form onsubmit= "return new_window(); " > <input type="text" name="tbValue"><a href="javascript:" onclick="Open();">Open http://www.dwww.cn </a> </form> </body>
answer.jsp
<script language="javascript" type="text/javascript"> function SetValue(value) { self.opener.document.all("tbValue").value=value; self.close(); } </script>
<body> Values:<br/> <a href="javascript:SetValue('1')">value 1</a><br/> <a href="javascript:SetValue('2')">value 2</a>
</body>
不可以跳轉(zhuǎn) <a href="javascript:;" onclick="javascript:ToUrl('http://www.jingzhengli.cn');"> location.href不跳轉(zhuǎn)測試1</a> <a href="javascript:void(0);" onclick="javascript:ToUrl('http://www.jingzhengli.cn');"> location.href不跳轉(zhuǎn)測試2</a>
可以跳轉(zhuǎn) <a href="javascript:void(0);" onclick="javascript:ToUrl('http://www.jingzhengli.cn');return false;"> location.href不跳轉(zhuǎn)測試3</a> <a href="#" onclick="javascript:ToUrl('http://www.jingzhengli.cn');"> location.href不跳轉(zhuǎn)測試4</a> <a href="###" onclick="javascript:ToUrl('http://www.jingzhengli.cn');"> location.href不跳轉(zhuǎn)測試5</a> 本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/muzai/archive/2010/11/22/6026786.aspx
第一種: <script language="javascript" type="text/javascript"> window.location.href="login.jsp?backurl="+window.location.href; </script>
第二種: <script language="javascript"> alert("返回"); window.history.back(-1); </script>
第三種: <script language="javascript"> window.navigate("top.jsp"); </script>
第四種: <script language="JavaScript"> self.location='top.htm'; </script>
第五種: <script language="javascript"> alert("非法訪問!"); top.location='xx.jsp'; </script>
|