How to Interact Flex with Java

Links to the original text: https://my.oschina.net/mohaiyong/blog/217753
Three flex4 andJava The way to communicate smoothly is:
flex communicates with ordinary java class RemoteObject;
Fl interacts with server HTTPService;
Flexible interacts with web service.
When you try to use flex to communicate with ordinary java classes, you usually use RemoteObject. The specific code snippets are as follows:
  package com.flex.demo;
/**
*The first function description: this class is used to implement flex communication with methods in common java classes
* @author Administrator
*/
//The above is a functional description of the head, you can not write.
<!--flex And ordinary java Class communication-->
<s:RemoteObject id="serv" destination="myservice" fault="serv_faultHandler(event)" result="serv_resultHandler(event)">
<properties>
<source>com.flex.demo.SimpleService</source>
</properties>
</s:RemoteObject>
[js] view plaincopy
<!--flex Interacting with the server HTTPService-->
<!--servlet Code-->
/**
* The second function description: The servlet is used to interact with flex
* @author Administrator
*/
@SuppressWarnings("serial")
public class SimpleServiceServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.getWriter().write("I'm a server.“);
}
}
Fl interacts with server HTTPService, flex-side code
<!-- flex Interacting with the server-->
<s:HTTPService id="service" fault="service_faultHandler(event)" result="service_resultHandler(event)"   url="http://localhost:8080/flexdemo/simpleServiceServlet">
</s:HTTPService>
<!--Third kinds flex And webservice interactive WebService-->
<!--flex And webservice Interactive call here for a weather forecast webservice-->
<s:WebService id="ws"
wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl"
fault="ws_faultHandler(event)"
result="ws_resultHandler(event)"
showBusyCursor="true">
<!-- call webservice Method<speration>-->
In addition, I would like to say that although the code segment for pop-up boxes is very simple, it is better not to omit them:
protected function service_faultHandler(event:FaultEvent):void{
Alert.show("The call failed:"+event.fault.message as String,"Prompt ");
}
protected function service_resultHandler(event:ResultEvent):void{
Alert.show("The call succeeded:"+event.result as String,"Prompt ");
}
<span style="font-family:Arial; background-color:#ffffff"></span>
 

Reproduced in: https://my.oschina.net/mohaiyong/blog/217753

Keywords: Java

Added by y.t. on Tue, 08 Oct 2019 11:18:28 +0300