<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    雪湖小札@blogjava

    心情與技術文檔同行 http://hi.baidu.com/jingleq

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      24 Posts :: 2 Stories :: 4 Comments :: 0 Trackbacks
    示例代碼下載:flex-struts.rar
    該代碼包含兩個項目,一個是web項目,一個是flex項目,使用workshop+flex builder2開發,主要演示了如下幾個特征:
    (1).flex獲取遠程url的xml數據,加載到DataGrid中。在解釋數據的時候,使用了actionscript的class.
    actionscript class文件代碼:
     package org.c2ome.flex.xml

     public class XmlDoc
     
    {
      private 
    var headStr :String = 
       
    "<?xml version='1.0' ?>" + 
       
    "<Msg>" + 
       
    "<data>";
      private 
    var footStr: String =
       
    "</data>" + 
       
    "</Msg>";
      private 
    var contentStr: String = "";

      public 
    function addData(key : String, value: String) : void {
       
    var nodeStr: String = 
        
    "<entry><key>" + key + "</key><value>" + value +"</value>" + "</entry>";
       contentStr 
    +=nodeStr;
      }

      public 
    function toXml() : XML {
       
    return new XML(headStr + contentStr + footStr);
      }

      public 
    function toString() :String {
       
    return headStr + contentStr + footStr;
      }
     
     }

    }

    flexj.mxml代碼:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
     
    <mx:Script>
      
    <![CDATA[
      import org.c2ome.flex.xml.XmlDoc;
      import mx.rpc.events.ResultEvent;
      import mx.controls.Alert;
      import flash.events.Event;
      import flash.net.URLLoader;
      import flash.net.URLRequest;
            private function loadApp():void {
       var loader:URLLoader = new URLLoader();
       var request:URLRequest = new URLRequest("http://localhost:8080/flexLogic.do?method=getBooks");
       var variables:URLVariables = new URLVariables();
       var x : XmlDoc = new XmlDoc();
       x.addData("name","c2one");
       x.addData("password","123456");
       variables.xmlDoc = x.toString();
       request.data = variables;
       request.method = "POST";
       loader.load(request);
       loader.addEventListener(Event.COMPLETE, onComplete);
            }
      private function onComplete(event:Event):void
      {
          var loader:URLLoader = event.target as URLLoader;
          if (loader != null) {
              var externalXML:XML = new XML(loader.data);
              bookdg.dataProvider = externalXML.data.entry.(key=="cc").value.Book;
           sysReturn.text = externalXML.data.entry.(key=="name").value.valueOf();
          }
          else {
              Alert.show("loader is not a URLLoader!");
          }
      }
      
    ]]>
     
    </mx:Script>
     
    <mx:DataGrid x="78.5" y="93" id="bookdg">
      
    <mx:columns>
       
    <mx:DataGridColumn headerText="name" dataField="@name"/>
       
    <mx:DataGridColumn headerText="price" dataField="@price"/>
      
    </mx:columns>
     
    </mx:DataGrid>
     
    <mx:Button x="78.5" y="292" label="Button" click="loadApp();"/>
     
    <mx:TextArea x="78" y="256" height="28" width="202.5" id="sysReturn"/>
    </mx:Application>
    (2).在web端根目錄配置跨域訪問控制:建文件crossdomain.xml
    <?xml version="1.0"?> 
    <!DOCTYPE cross-domain-policy
    SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"
    >
    <cross-domain-policy>
        
    <allow-access-from domain="*" />
    </cross-domain-policy>
    (3).在web端使用了betwixt來處理xml與對象,看com.c2one.util.XMLUtil
    package com.c2one.util;

    import java.beans.IntrospectionException;
    import java.io.IOException;
    import java.io.StringReader;
    import java.io.StringWriter;
    import java.util.Map;

    import org.apache.commons.betwixt.io.BeanReader;
    import org.apache.commons.betwixt.io.BeanWriter;
    import org.xml.sax.SAXException;

    public class XMLUtil {

        
    public static String beanParser(String info, String exeCode,
                Map
    <String, Object> data) throws IOException, SAXException,
                IntrospectionException 
    {
            String result 
    = "";
            StringWriter outputWriter 
    = new StringWriter();
            outputWriter.write(
    "<?xml version='1.0' ?>");
            BeanWriter beanWriter 
    = new BeanWriter(outputWriter);
            beanWriter.getXMLIntrospector().getConfiguration()
                    .setAttributesForPrimitives(
    true);
            beanWriter.getBindingConfiguration().setMapIDs(
    false);
            beanWriter.enablePrettyPrint();
            ResponseEntity entity 
    = new ResponseEntity(info, exeCode, data);
            beanWriter.write(
    "Msg", entity);
            result 
    = outputWriter.toString();
            outputWriter.close();
            
    return result;
        }


        
    public static RequestEntity stringParser(String str)
                
    throws IntrospectionException, IOException, SAXException {
            StringReader xmlReader 
    = new StringReader(str);
            BeanReader beanReader 
    = new BeanReader();
            beanReader.getXMLIntrospector().getConfiguration()
                    .setAttributesForPrimitives(
    true);
            beanReader.getBindingConfiguration().setMapIDs(
    false);
            beanReader.registerBeanClass(
    "Msg", RequestEntity.class);
            RequestEntity obj 
    = (RequestEntity) beanReader.parse(xmlReader);
            
    return obj;
        }

    }
    posted on 2007-11-12 10:27 csnowfox 閱讀(2153) 評論(1)  編輯  收藏

    Feedback

    # re: struts與flex通過xml交互模型 2008-04-12 10:30 豆抓
    路過,哈  回復  更多評論
      


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 在线观看日本亚洲一区| 亚洲?V无码乱码国产精品| 最近免费中文字幕mv电影| 1000部啪啪未满十八勿入免费 | 免费人成网上在线观看| 特a级免费高清黄色片| 免费黄网站在线观看| 野花高清在线观看免费3中文 | 日韩中文字幕免费| 亚洲综合网站色欲色欲| 亚洲无砖砖区免费| 产传媒61国产免费| 亚洲精品无码精品mV在线观看| 亚洲精品韩国美女在线| 久久高潮一级毛片免费| 免费看黄视频网站| 亚洲AV无码第一区二区三区| 亚洲久热无码av中文字幕| 男人都懂www深夜免费网站| 国产乱弄免费视频| 亚洲乱码一二三四区国产| 91成人免费观看在线观看| 国产免费午夜a无码v视频| 亚洲五月午夜免费在线视频| 免费理论片51人人看电影| 亚洲va无码va在线va天堂| 99国产精品视频免费观看| 亚洲欧洲日产国码无码久久99| 亚洲国产一区二区三区在线观看| 四虎影视在线影院在线观看免费视频| 亚洲精品无码99在线观看| 亚洲依依成人亚洲社区| 亚洲国产精品成人| 乱人伦中文视频在线观看免费| 免费观看的毛片大全| 亚洲成a人片在线不卡一二三区| 久久99亚洲综合精品首页| 麻豆va在线精品免费播放| 色播在线永久免费视频| 成年女人A毛片免费视频| 久久亚洲中文字幕精品一区四 |