日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
初析Struts2中的Ajax開發(fā)實(shí)例

  Web2.0的隨波逐流,Ajax那是大放異彩,Struts2框架自己整合了對Ajax的原生支持(struts 2.1.7+,之前的版本可以通過插件實(shí)現(xiàn)),框架的整合只是使得JSON的創(chuàng)建變得異常簡單,并且可以簡單的融入到Struts2框架中,當(dāng)然這只是在我們需要JSON的時(shí)候才會顯得流光溢彩。

創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供梁山網(wǎng)站建設(shè)、梁山做網(wǎng)站、梁山網(wǎng)站設(shè)計(jì)、梁山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、梁山企業(yè)網(wǎng)站模板建站服務(wù),十余年梁山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

  首先不談Struts2的原生支持,我們自己寫一個(gè)ajax示例,使用異步請求,直接請求action動作:

  InfoAction.java

 
 
 
 
  1. packagecn.codeplus.action;importcom.opensymphony.xwork2.ActionSupport;  
  2. publicclassInfoAction extendsActionSupport {
  3. privatestaticfinallongserialVersionUID =1359090410097337654L;  
  4. publicString loadInfo() {returnSUCCESS;  
  5.   }  
  6.   } 

InfoAction僅僅是簡單的返回"success"。

  index.jsp

 
 
 
 
  1.    
  2.    
  3.     "> 
  4.   獲取 
  5.    
  6.    
  7.    
  8.    
  9.    
  10.   
 
  •    
  •    
  •   index.jsp包含一個(gè)按鈕,點(diǎn)擊按鈕則會觸發(fā)異步請求事件。

      struts.xml

     
     
     
     
    1.    
    2.    
    3.   /info.jsp 
    4.    
    5.    

      可見上面的異步請求的結(jié)果將會是加載info.jsp,info.jsp只是一個(gè)簡單網(wǎng)頁,不列出了。

      運(yùn)行效果如下:

    單擊獲取之后:

    此時(shí)的頁面源代碼:

      

    標(biāo)簽中嵌套了標(biāo)簽,不符合規(guī)范,其實(shí)我們只要吧info.jsp寫的沒有<title>之類的標(biāo)簽,就不會出現(xiàn)這種情況了。</p><p>  以上說的異步請求僅適用于請求單個(gè)文件,如果我們請求的是動態(tài)數(shù)據(jù),并且數(shù)據(jù)需要以JSON格式返回,上面的方法將會顯得力不從心,這是struts2的原生支持就得出馬了。</p><p>  使用struts2的ajax,必須在項(xiàng)目中引入struts2-json-plugin-2.2.1.jar,在版本2.1.7+都一句綁定在struts2發(fā)行包里面了(之前的版本可以在這下載)。記住,要引入struts2-json-plugin-2.2.1.jar。</p><p>  這次我們使用另一個(gè)例子,模擬加載評論:</p><p>  dto對象,Comment.java</p><pre> <ol> <li>packagecn.codeplus.po;  </li> <li>publicclassComment {  </li> <li>privatelongid;privateString nickname;</li> <li>privateString content;publiclonggetId() {returnid;  </li> <li>  }  </li> <li>publicvoidsetId(longid) {</li> <li>this.id =id;  </li> <li>  }  </li> <li>publicString getNickname() {returnnickname;  </li> <li>  }  </li> <li>publicvoidsetNickname(String nickname) {</li> <li>this.nickname =nickname;  </li> <li> }  </li> <li>publicString getContent() {returncontent;  </li> <li>  }  </li> <li>publicvoidsetContent(String content) {</li> <li>this.content =content;  </li> <li>  }  </li> <li>  } </li> </ol></pre><p>  新的InfoAction.java </p><pre> <ol> <li>packagecn.codeplus.action;  </li> <li>importjava.util.ArrayList;importjava.util.List;  </li> <li>importcn.codeplus.po.Comment;  </li> <li>importcom.opensymphony.xwork2.ActionSupport;  </li> <li>publicclassInfoAction extendsActionSupport {  </li> <li>privatestaticfinallongserialVersionUID =1359090410097337654L;  </li> <li>privateList<Comment>comments =newArrayList<Comment>();//沒getter and setter方法的屬性不會被串行化到JSON  </li> <li>  @SuppressWarnings("unused")  </li> <li>privateString title;//!??!使用transient修飾的屬性也會被串行化到JSONprivatetransientString content;publicString loadInfo() {  </li> <li>  title="123木頭人";  </li> <li>  content="你是木頭人,哈哈。";  </li> <li>  loadComments();returnSUCCESS;  </li> <li>  }/*** 加載留言信息*/  </li> <li>  privatevoidloadComments() {  </li> <li>  Comment com1 =newComment();  </li> <li>  com1.setContent("很不錯(cuò)嘛");  </li> <li>  com1.setId(1);  </li> <li>  com1.setNickname("納尼");  </li> <li>  Comment com2 =newComment();  </li> <li>  com2.setContent("喲西喲西");  </li> <li>  com2.setId(2);  </li> <li>  com2.setNickname("小強(qiáng)");  </li> <li>  comments.add(com1);  </li> <li>  comments.add(com2);  </li> <li>  }publicList<Comment>getComments() {returncomments;  </li> <li>  }publicvoidsetComments(List<Comment>comments) {this.comments =comments;  </li> <li>  }publicstaticlonggetSerialversionuid() {returnserialVersionUID;  </li> <li>  }publicString getContent() {returncontent;  </li> <li>  }publicvoidsetContent(String content) {this.content =content;  </li> <li>  }  </li> <li>  }  </li> <li>  index.jsp還是那個(gè)index.jsp。(*^__^*) 嘻嘻……  </li> <li>  struts.xml變化挺大:  </li> <li>  <package name="ajaxDemo"extends="json-default"> </li> <li>  <action name="loadInfo"class="cn.codeplus.action.InfoAction"method="loadInfo"> </li> <li>  <result name="success"type="json"></result> </li> <li>  </action> </li> <li>  </package> </li> </ol></pre><p>  在struts.xml中:</p><p>  首先,package extends由struts-default轉(zhuǎn)變?yōu)閖son-default,這是必須的,只用在json-default中才包含下面使用的result type為 json。</p><p>  然后就是result類型需顯示指明為json,result標(biāo)簽內(nèi),無需指明視圖指向的界面。</p><p>  ***就是運(yùn)行結(jié)果啦:</p><p>  點(diǎn)擊“獲取”按鈕之后:</p></p><p>  可見comments對象和content對象都被串行化到JSON數(shù)據(jù)了,不知道是不是版本的問題,很多資料都說使用transient修飾的屬性不會被串行化到JSON的。</p><p>  為了使content對象不被串行化到JSON,在不能舍棄其getter setter方法的時(shí)候,我們可以這樣在content的getter方法上面加上注解:@JSON(serialize=false)</p><pre> <ol> <li>  ...  </li> <li>  @JSON(serialize=false)publicString getContent() {returncontent;  </li> <li>  }publicvoidsetContent(String content) {this.content =content;  </li> <li>  }  </li> <li>  ... </li> </ol></pre><p>  這時(shí)的結(jié)果如下:</p></p><p>  @JSON和json類型的result都還有很多可選項(xiàng),無非就是串行化誰,不串行化誰,返回?cái)?shù)據(jù)的MIME類型,讀者可以自行參考相關(guān)文檔。</p><p>  獲取到JSON數(shù)據(jù)了,下一步就是在前臺使用js處理JSON數(shù)據(jù)了,本人JS不精,喜歡使用jQuery解析,如有興趣,且聽下回分解jQuery解析JSON數(shù)據(jù)。</p> <br> 當(dāng)前標(biāo)題:初析Struts2中的Ajax開發(fā)實(shí)例 <br> URL分享:<a href="http://m.5511xx.com/article/ccdchjg.html">http://m.5511xx.com/article/ccdchjg.html</a> </div> <div id="8vcjhg7" class="hot_new"> <div id="meelkbj" class="page_title clearfix"> <h3>其他資訊</h3> </div> <div id="67g1s9v" class="news_list clearfix"> <ul> <li> <a href="/article/djioecj.html">「MSSQL雙備份」:安全保障系統(tǒng)的關(guān)鍵(mssql雙備份)</a> </li><li> <a href="/article/djioesi.html">域名被限制訪問怎么解決?(如何解決域名被列入訪問黑名單)</a> </li><li> <a href="/article/djioedc.html">便宜vps主機(jī)租用怎么確保穩(wěn)定性</a> </li><li> <a href="/article/djioeei.html">英國服務(wù)器租用</a> </li><li> <a href="/article/djioeee.html">論Web2.0時(shí)代的PHP:優(yōu)點(diǎn)還是問題?</a> </li> </ul> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> <!-- 底部信息 --> <div id="ilcru62" class="footer wow fadeInUp"> <div id="u2kb2ho" class="rowFluid"> <div id="b9oxnds" class="span12"> <div id="d4ulayh" class="container"> <div id="zaipxxe" class="footer_content"> <div id="8woecsa" class="span4 col-xm-12"> <div id="do1klj9" class="footer_list"> <div id="pqytarg" class="span6"> <div id="tlkagx6" class="bottom_logo"><img src="/Public/Home/images/ewm.jpg" alt="微信服務(wù)號二維碼" /></div> </div> <div id="ph9ld9w" class="span6 col-xm-12"> <div id="tmkkarj" class="quick_navigation"> <div id="zahjaiy" class="quick_navigation_title">快速導(dǎo)航</div> <ul> <li><a title="外貿(mào)網(wǎng)站建設(shè)" target="_blank">外貿(mào)網(wǎng)站建設(shè)</a></li><li><a title="成都光華機(jī)房" target="_blank">成都光華機(jī)房</a></li><li><a title="tpbzx.cn" target="_blank">tpbzx.cn</a></li><li><a title="scdkfx.com" target="_blank">scdkfx.com</a></li><li><a title="百度推廣公司" target="_blank">百度推廣公司</a></li><li><a title="成都發(fā)電機(jī)維修保養(yǎng)" target="_blank">成都發(fā)電機(jī)維修保養(yǎng)</a></li><li><a title="成都水晶字" target="_blank">成都水晶字</a></li><li><a title="資陽發(fā)電機(jī)組租用" target="_blank">資陽發(fā)電機(jī)組租用</a></li><li><a href="http://chengdu.cdcxhl.cn/dingzhi/ " title="成都定制網(wǎng)站" target="_blank">成都定制網(wǎng)站</a></li><li><a title="湖北施工照明燈" target="_blank">湖北施工照明燈</a></li><li><a title="達(dá)州服務(wù)器托管" target="_blank">達(dá)州服務(wù)器托管</a></li> </ul> </div> </div> </div> </div> <div id="mq8chxe" class="span4 col-xm-6 col-xs-12"> <div id="ozqge9o" class="footer_list"> <div id="jsjljqh" class="footer_link"> <div id="cemciyy" class="footer_link_title">友情鏈接</div> <ul id="frientLinks"> <a title="網(wǎng)站制作" target="_blank">網(wǎng)站制作</a> <a title="網(wǎng)站建設(shè)" target="_blank">網(wǎng)站建設(shè)</a> <a title="成都網(wǎng)絡(luò)推廣" target="_blank">網(wǎng)絡(luò)推廣</a> <a title="成都網(wǎng)站推廣" target="_blank">網(wǎng)站推廣</a> <a title="成都微信小程序開發(fā)" target="_blank">小程序開發(fā)</a> <a title="創(chuàng)新互聯(lián)網(wǎng)站欄目導(dǎo)航" target="_blank">網(wǎng)站導(dǎo)航</a> </ul> <div id="pr7gfvw" class="footer_link_title">網(wǎng)站建設(shè)</div> <ul id="frientLinks"> <li><a href="/">四川平武建站</a></li> <li><a title="創(chuàng)新互聯(lián)網(wǎng)站欄目導(dǎo)航" target="_blank">網(wǎng)站導(dǎo)航</a></li> </ul> </div> </div> </div> <div id="eeuj4f9" class="span4 col-xm-6 col-xs-12"> <div id="wqffwus" class="footer_list"> <div id="atkrzqp" class="footer_cotact"> <div id="bcts8gg" class="footer_cotact_title">聯(lián)系方式</div> <ul> <li><span id="gprip3o" class="footer_cotact_type">企業(yè):</span><span id="aluar3u" class="footer_cotact_content">四川綿陽平武網(wǎng)站建設(shè)工作室</span></li> <li><span id="jkbzyzr" class="footer_cotact_type">地址:</span><span id="dvddarx" class="footer_cotact_content">成都市青羊區(qū)太升南路288號</span></li> <li><span id="u92oels" class="footer_cotact_type">電話:</span><span id="gyxo89l" class="footer_cotact_content"><a href="tel:18980820575" class="call">18980820575</a></span></li> <li><span id="isari1t" class="footer_cotact_type">網(wǎng)址:</span><span id="irtjg2i" class="footer_cotact_content"><a href="/" title="四川平武網(wǎng)站建設(shè)">m.5511xx.com</a></span></li> </ul> </div> </div> </div> </div> </div> <div id="blb4gnv" class="copyright"> <p>公司名稱:四川綿陽平武網(wǎng)站建設(shè)工作室 聯(lián)系電話:18980820575</p> <p><a target="_blank" rel="nofollow">網(wǎng)站備案號:蜀ICP備2024061352號-3</a></p> <p>四川平武建站 四川平武網(wǎng)站建設(shè) 四川平武網(wǎng)站設(shè)計(jì) 四川平武網(wǎng)站制作 <a target="_blank">成都做網(wǎng)站</a></p> </div> </div> </div> </div> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://m.5511xx.com/" title="日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区">日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区</a> <div class="friend-links"> </div> </div> </footer> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body><div id="rhqpp" class="pl_css_ganrao" style="display: none;"><form id="rhqpp"><dl id="rhqpp"><label id="rhqpp"><pre id="rhqpp"></pre></label></dl></form><ul id="rhqpp"><td id="rhqpp"><var id="rhqpp"><small id="rhqpp"></small></var></td></ul><button id="rhqpp"></button><s id="rhqpp"><label id="rhqpp"><tt id="rhqpp"><rt id="rhqpp"></rt></tt></label></s><i id="rhqpp"></i><kbd id="rhqpp"></kbd><rt id="rhqpp"><nobr id="rhqpp"><em id="rhqpp"><s id="rhqpp"></s></em></nobr></rt><pre id="rhqpp"><strong id="rhqpp"><label id="rhqpp"><samp id="rhqpp"></samp></label></strong></pre><li id="rhqpp"><ins id="rhqpp"><input id="rhqpp"><optgroup id="rhqpp"></optgroup></input></ins></li><table id="rhqpp"><em id="rhqpp"><thead id="rhqpp"><dfn id="rhqpp"></dfn></thead></em></table><button id="rhqpp"></button><input id="rhqpp"></input><dfn id="rhqpp"></dfn><rt id="rhqpp"></rt><code id="rhqpp"></code><thead id="rhqpp"><optgroup id="rhqpp"><dfn id="rhqpp"><strike id="rhqpp"></strike></dfn></optgroup></thead><rp id="rhqpp"></rp><dfn id="rhqpp"><ul id="rhqpp"><td id="rhqpp"><var id="rhqpp"></var></td></ul></dfn><samp id="rhqpp"></samp><dfn id="rhqpp"></dfn><small id="rhqpp"><samp id="rhqpp"><rt id="rhqpp"><nobr id="rhqpp"></nobr></rt></samp></small><small id="rhqpp"><delect id="rhqpp"><dfn id="rhqpp"><noframes id="rhqpp"></noframes></dfn></delect></small><th id="rhqpp"><button id="rhqpp"><i id="rhqpp"><tbody id="rhqpp"></tbody></i></button></th><video id="rhqpp"></video><nobr id="rhqpp"><delect id="rhqpp"><legend id="rhqpp"><noframes id="rhqpp"></noframes></legend></delect></nobr><nobr id="rhqpp"><delect id="rhqpp"><legend id="rhqpp"><th id="rhqpp"></th></legend></delect></nobr><noframes id="rhqpp"><td id="rhqpp"><i id="rhqpp"><em id="rhqpp"></em></i></td></noframes><dl id="rhqpp"><dfn id="rhqpp"><sup id="rhqpp"><strike id="rhqpp"></strike></sup></dfn></dl><tt id="rhqpp"></tt><dl id="rhqpp"></dl><kbd id="rhqpp"></kbd><i id="rhqpp"><tbody id="rhqpp"><delect id="rhqpp"><s id="rhqpp"></s></delect></tbody></i><code id="rhqpp"></code><strong id="rhqpp"><dfn id="rhqpp"><td id="rhqpp"><var id="rhqpp"></var></td></dfn></strong><small id="rhqpp"></small><var id="rhqpp"></var><code id="rhqpp"><small id="rhqpp"><wbr id="rhqpp"><dfn id="rhqpp"></dfn></wbr></small></code><strong id="rhqpp"></strong><em id="rhqpp"><legend id="rhqpp"><th id="rhqpp"><tt id="rhqpp"></tt></th></legend></em><dl id="rhqpp"><label id="rhqpp"><pre id="rhqpp"><strike id="rhqpp"></strike></pre></label></dl><abbr id="rhqpp"><output id="rhqpp"><menu id="rhqpp"><form id="rhqpp"></form></menu></output></abbr><small id="rhqpp"><delect id="rhqpp"><dfn id="rhqpp"><noframes id="rhqpp"></noframes></dfn></delect></small><sup id="rhqpp"></sup><sup id="rhqpp"></sup><kbd id="rhqpp"></kbd><samp id="rhqpp"></samp><label id="rhqpp"><button id="rhqpp"><tfoot id="rhqpp"><pre id="rhqpp"></pre></tfoot></button></label><button id="rhqpp"></button><i id="rhqpp"><pre id="rhqpp"><delect id="rhqpp"><s id="rhqpp"></s></delect></pre></i><small id="rhqpp"><tt id="rhqpp"><rt id="rhqpp"><nobr id="rhqpp"></nobr></rt></tt></small><li id="rhqpp"><center id="rhqpp"><label id="rhqpp"><optgroup id="rhqpp"></optgroup></label></center></li><label id="rhqpp"><optgroup id="rhqpp"><sup id="rhqpp"><fieldset id="rhqpp"></fieldset></sup></optgroup></label><ul id="rhqpp"><fieldset id="rhqpp"><table id="rhqpp"><ins id="rhqpp"></ins></table></fieldset></ul><acronym id="rhqpp"></acronym><fieldset id="rhqpp"><var id="rhqpp"><ins id="rhqpp"><dl id="rhqpp"></dl></ins></var></fieldset><em id="rhqpp"><legend id="rhqpp"><th id="rhqpp"><samp id="rhqpp"></samp></th></legend></em><fieldset id="rhqpp"><var id="rhqpp"><ins id="rhqpp"><thead id="rhqpp"></thead></ins></var></fieldset><fieldset id="rhqpp"><var id="rhqpp"><ins id="rhqpp"><thead id="rhqpp"></thead></ins></var></fieldset><small id="rhqpp"><rp id="rhqpp"><rt id="rhqpp"><pre id="rhqpp"></pre></rt></rp></small><acronym id="rhqpp"></acronym><acronym id="rhqpp"></acronym><abbr id="rhqpp"><sup id="rhqpp"><menu id="rhqpp"><li id="rhqpp"></li></menu></sup></abbr><fieldset id="rhqpp"><code id="rhqpp"><ins id="rhqpp"><thead id="rhqpp"></thead></ins></code></fieldset><thead id="rhqpp"></thead><menu id="rhqpp"></menu><kbd id="rhqpp"></kbd><samp id="rhqpp"><dl id="rhqpp"><em id="rhqpp"><em id="rhqpp"></em></em></dl></samp><strike id="rhqpp"></strike><sup id="rhqpp"></sup><thead id="rhqpp"><strong id="rhqpp"><ul id="rhqpp"><td id="rhqpp"></td></ul></strong></thead><li id="rhqpp"><center id="rhqpp"><label id="rhqpp"><abbr id="rhqpp"></abbr></label></center></li><center id="rhqpp"><dl id="rhqpp"><abbr id="rhqpp"><output id="rhqpp"></output></abbr></dl></center><thead id="rhqpp"></thead><dl id="rhqpp"></dl><optgroup id="rhqpp"><noframes id="rhqpp"><strike id="rhqpp"><var id="rhqpp"></var></strike></noframes></optgroup><th id="rhqpp"><tt id="rhqpp"><rt id="rhqpp"><nobr id="rhqpp"></nobr></rt></tt></th><s id="rhqpp"><th id="rhqpp"><tt id="rhqpp"><rt id="rhqpp"></rt></tt></th></s><center id="rhqpp"></center><pre id="rhqpp"></pre><center id="rhqpp"><thead id="rhqpp"><abbr id="rhqpp"><output id="rhqpp"></output></abbr></thead></center><delect id="rhqpp"></delect><noframes id="rhqpp"><tt id="rhqpp"><code id="rhqpp"><nobr id="rhqpp"></nobr></code></tt></noframes><tfoot id="rhqpp"></tfoot><menu id="rhqpp"></menu><legend id="rhqpp"></legend><code id="rhqpp"></code><thead id="rhqpp"></thead><dfn id="rhqpp"></dfn><optgroup id="rhqpp"><ul id="rhqpp"><sup id="rhqpp"><form id="rhqpp"></form></sup></ul></optgroup><wbr id="rhqpp"><dfn id="rhqpp"><dfn id="rhqpp"><strike id="rhqpp"></strike></dfn></dfn></wbr><noframes id="rhqpp"></noframes><th id="rhqpp"><samp id="rhqpp"><rt id="rhqpp"><em id="rhqpp"></em></rt></samp></th><input id="rhqpp"><video id="rhqpp"><acronym id="rhqpp"><label id="rhqpp"></label></acronym></video></input><dfn id="rhqpp"><samp id="rhqpp"><var id="rhqpp"><em id="rhqpp"></em></var></samp></dfn><thead id="rhqpp"></thead><nobr id="rhqpp"><pre id="rhqpp"><legend id="rhqpp"><small id="rhqpp"></small></legend></pre></nobr><em id="rhqpp"></em><abbr id="rhqpp"><output id="rhqpp"><menu id="rhqpp"><form id="rhqpp"></form></menu></output></abbr><samp id="rhqpp"></samp><thead id="rhqpp"></thead></div> </html>