<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 豆抓
    路過,哈  回復  更多評論
      


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


    網站導航:
     
    主站蜘蛛池模板: 午夜不卡久久精品无码免费| 亚洲精品乱码久久久久久| 日本二区免费一片黄2019| 亚洲综合久久1区2区3区| 理论片在线观看免费| 四虎永久成人免费影院域名| 亚洲视频免费在线播放| 亚洲一区中文字幕在线观看| 欧洲人成在线免费| 国产AV无码专区亚洲AVJULIA| 日韩精品无码免费专区午夜| 亚洲成色在线综合网站| 一区二区三区四区免费视频| 亚洲精品美女视频| 99久久免费精品国产72精品九九| 亚洲kkk4444在线观看| 在线观看亚洲免费视频| 黄色一级视频免费观看| 亚洲夜夜欢A∨一区二区三区| a在线视频免费观看| 久久亚洲精品无码AV红樱桃| 三年片在线观看免费观看高清电影| 亚洲中文无码卡通动漫野外| 免费看一级做a爰片久久| 女人隐私秘视频黄www免费| 久99久精品免费视频热77| 4444亚洲国产成人精品| 国产精品免费观看久久| 特级无码毛片免费视频| 亚洲AV永久无码精品一百度影院 | 91免费国产精品| 99亚洲精品高清一二区| 四虎影视免费永久在线观看| 久久精品熟女亚洲av麻豆| 亚洲午夜久久久影院伊人| 日韩精品人妻系列无码专区免费 | 永久在线观看免费视频| 亚洲国产精品xo在线观看| 你好老叔电影观看免费| 精品亚洲国产成人| 国产精品亚洲mnbav网站 |