BlazeDS Integration Flex__blazeds

Source: Internet
Author: User
This article turns from: http://www.cnblogs.com/hoojo/archive/2011/09/16/2178802.html BlazeDS Consolidated Flex HelloWorld sample

Development environment:

System:windows

webbrowser:ie6+, firefox3+

Java EE server:tomcat5.0.2.8, tomcat6

Ide:eclipse, MyEclipse 8

Flex Ide:flash Builder 4

blazeds:4.5

To develop a dependent library:

JavaEE5, BlazeDS 4.5

Email:hoojo_@126.com

Blog:http://blog.csdn.net/ibm_hoojo

http://hoojo.cnblogs.com/

First, preparatory work

1, first to provide the relevant jar package

Java server side needs to provide blazeds-related configuration and Jar packs

Download Address: Http://opensource.adobe.com/wiki/display/blazeds/download+blazeds+trunk

After downloading, unzip you can see such a directory

Docs is the document.

Resource is the source code

SampleDb is the database used by the example to run Startdb.bat to start the database

Tomcat is built into Tomcat and if you don't have Tomcat you can use it, and there are samples of samples in Tomcat's WebApps directory.

Blazeds.war is BlazeDS's core files, libraries, you can put this war into Tomcat WebApps directory, will automatically extract. Of course, you can also manually unzip yourself.

Blazeds-spring.war is a configuration that is integrated with spring

Ds-console.war is a blazeds console program.

Samples.war is an official example.

Samples-spring.war is a consolidated example of spring and BlazeDS , deploying server-side Programs

1. Create a new Javaweb Project project and add the following jar package to the Web-inf/lib directory

These jar packs can be found in the Lib directory in the Blazeds.war package

2, then you need to copy the Web-inf directory in the Blazeds.war package to the Flex directory under the current project Web-inf

3, the Web-inf directory in the Blazeds.war package web.xml configuration, add to the current project Web.xml file

4, the last basic style is as follows

5, finally you release the current project, if there is no error indicates that your server-side deployment succeeded.

6, write a HelloWorld Java program. The code is as follows

Package Com.hoo.flex;
/**
* <b>function:</b> HelloWorld Example
* @author Hoojo
* @createDate 2011-8-31 06:11:27
* @file Helloworld.java
* @package Com.hoo.flex
* @project Blazedsserver
* @blog Http://blog.csdn.net/IBM_hoojo
* @email hoojo_@126.com
* @version 1.0
*/
public class HelloWorld {
    
    Public HelloWorld () {
    }
    
    public string SayHello (string name) {
        Return "[" + name + "] Say hello!";
    }
}

A SayHello method is used to receive an argument. Third, Flex client program

1, create a flex project, in the selection of server technology, you need to choose Java. Then use the Java technology on the hook, then select BlazeDS. Click Next Next

2. Configure the root folder, which is the location of the Java EE Server-side release program in Tomcat. I am here in the blazedsserver of Tomcat WebApps, Blazedsserver is my server-side program. The root URL is the URL that accesses the server-side program, the context directory corresponds to the project name, and finally the output folder directory, which is the directory where the flex file was last saved in Tomcat.

3, finally you need to set the server-side Services-config.xml path to the compilation parameters, this is very important. If you do not set it, then you need to set the endpoint when you call BlazeDS with RemoteObject later. The settings are as follows:

-services is the parameter key, and the following string is the value. I am here to set the path of the Services-config.xml that Blazedsserver publishes to the Tomcat directory.

4, the compilation of Flex front-end code, the code is as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" viewsourceurl= "Blazedshelloworld.mxml" Absolute "minwidth=" 955 "minheight=" >
    <mx:Script>
        <! [cdata[
            Import Mx.controls.Alert;
            Import Mx.rpc.AsyncToken;
            Import mx.rpc.events.ResultEvent;
            
            Private Function Faulthandler (event:event): void {
                Alert.show (Event.tostring (), event.type);
            }
            
            Private Function Resulthandler (event:resultevent): void {
                Event.result is the server-side return object
                Result.text = "message:" + event.result.toString ();
            }
            
            Private Function Sendhandler (): void {
                Helloremoteobject.sayhello (Username.text);
            }        
        ]]>
    </mx:Script>
    
    <!--when the project does not set the compiler-service parameters or-context-root parameters, you need to set the endpoint parameters manually-->
    
        
        
        
        result= "Resulthandler (event)"
        Showbusycursor= "true"/>
    <mx:panel x= "y=" width= "272" height= "148" layout= "absolute" title= "blazeds Remote HelloWorld Sample" >
        <mx:label x= "y=" text= "Please enter a name"/>
        <mx:textinput x= "y=" id= "UserName"/>
        <mx:button x= "184" y= "label=" send "click=" Sendhandler () "/>"
        <mx:text x= "y=" id= "result"/>
    </mx:Panel>    
</mx:Application>

First you need to configure the Java server-side HelloWorld program in Flex's Remoting-config.xml, configured as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
    class= "Flex.messaging.services.RemotingService" >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.