1. Compile the background Java processing method:
Create a com package under the SRC File
Create a class file under COM and name it "hello"
Add processing code:
PackageCom;
Public classHello {
PublicString Hello (string name ){
System.Out. Println ("flex calls Java! Name = "+ name );
Return"Hello" + name;
}
}
2. Configure remoting-config.xml
Add code
<Destination ID ="Hello">
<Properties>
<Source>
Com. Hello
</Source>
</Properties>
</Destination>
As follows:
3. Modify the flexj2ee. mxml file under flex_src
<? XML version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx "minwidth =" 955 "minheight =" 600 "> <FX: declarations> <! -- Place a non-visual element (such as a service or value object) Here --> <s: remoteobject Destination = "hello" id = "hell_ro" result = "GG (Event) "endpoint =" http: // localhost: 8089/flexj2ee/messagebroker/AMF "> </S: remoteobject> </FX: declarations> <FX: SCRIPT> <! [CDATA [import MX. RPC. events. resultevent; import MX. controls. alert; Private function Gg (E: resultevent): void {var backtext: String = E. result as string; backtxt. TEXT = backtext;} protected function remotingsayhello (Event: mouseevent): void {var sname: String = nameinput. text; hell_ro.hello (sname) ;}]> </FX: SCRIPT> <s: textarea id = "backtxt" x = "109" Y = "122" Height = "99"/> <s: button label = "send" Click = "remotingsayhello (Event) "x =" 110 "Y =" 243 "/> <s: textinput id =" nameinput "x =" 109 "Y =" 73 "/> <s: label x = "47" Y = "75" text = "rieciver:"/> <s: label x = "47" Y = "36" text = "this is my first flexj2ee project. Welcome to my blog http://blog.csdn.net/kkkloveyou"/> </S: Application>
4. Open http: // localhost: 8089/flexj2ee/flex/flexj2ee.html
Enter "may" in the rieciver input box.
Click "send"
The following "Hello May" is returned, indicating that flex has successfully communicated with Java.
5. the console output is as follows:
Full download: http://download.csdn.net/detail/kkkloveyou/4072746