「flex连接java」flex怎么使用
今天给各位分享flex连接java的知识,其中也会对flex怎么使用进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
flex 用socket连接JAVA时 的安全沙箱问题
关于Flex安全沙箱问题的解决最近遇到了Flex安全沙箱问题,找了很多资料发现不是都是和我的程序相关,我的程序需要socket连接,而大多数讲的都是跨域文件读取的。我就把这些方法都总结出来:跨域文件读取方法一:在目标服务器上布署crossdomain.xml文件(我用的此方法很管用,放上就没问题了)需要远程服务根目录定义有crossdomain.xml文件,如下:?xmlversion="1.0"encoding="UTF-8"?cross-domain-policyallow-access-fromdomain="*"//cross-domain-policy方法二:使用代理,把Flex要访问的远程文件通过asp,php,jsp等脚本读取到本地,然后再由Flex去访问;方法三:使用Adobeflashplayer9打开程序后,点击菜单栏中文件-创建播放器...即生成exe文件,运行exe文件即可突破安全限制;方法四:1、找到这个文件夹:c:\DocumentsandSettings\UserName\ApplicationData\Macromedia\FlashPlayer\#Security2、在其下建立一个名为"FlashPlayerTrust"的文件夹3、在"FlashPlayerTrust"文件夹下新建一TXT文件,内容如下:c:\d:\e:\f:\4、将该txt文件命名为:"myTrustFiles.cfg"再打开你硬盘里的SWF文件,就不会出现那个烦人的安全设置提示窗口了!方法五:用HttpService它默认是有Proxy的,需要配置flex-config.xml,里面有一段:http-service-proxywhitelist………………/whitelist/http-service-proxy这个是白名单,一般情况下是注释掉的,也就是默认只有本地的http://{localserver}/*和https://{localserver}/*可以访问。其他的需要在flex-config.xml里的自行修改成需要的就可以了。访问本地自然不会跨域,不过你肯定访问局域网其他机器了,所以是依照白名单规则,属于跨域Socket沙箱问题在Flex安全沙箱中使用Socket进行通信时,也会受到Flash9的新安全策略的困扰.解决方法不能像在Web服务器中布置一个crossdomain.xml来解决,或是在服务器上专门开启843端口来提供安全策略.有一种方法就是在接收到客户端的连接后,向其发送安全策略.比如我是用JAVA来开发,客户端的Flex会先搜索同域,及服务器的843口,看是否能得到安全策略,这时候Socket是先建立好的,可以在接收到Socket,即Accept事件发生是,马上向其发送策略串,否则客户端就会因为安全策略不过关,于断开,如果成功获取策略,则客户端将断掉先前的那次Socket,再真正进行程序中你要求的Socket连接请求.
flex与java到底是怎么结合的 什么是flex 数据绑定java
flex是前端框架 java是一门 语言 还是不要把基本概念混淆
flex所谓于java结合 是指的 前端的flex应用 于 后台java应用程序 通讯
flex 数据绑定java 这个 说法也不妥当 “数据绑定”是flex框架的一个特色功能 是指 可以 将一个变量 绑定到 组件的某个 可绑定属性上 变量发生变化 绑定的目标会自动更新 。所谓的绑定到java 准确的 应该是指 flex本地对象 映射为 后台java对象 这个在使用remoteObject通讯是才会用到
flex调用Java方法连接sqlserver
基于blazeDS的flex4与spring的程序实例步骤
环境:
jdk1.6
j2ee1.5
spring2.5.6
blazeDS3.3
tomcat6.0
flex4
myeclipse8.5
flashBuilder4
步骤:
一、 启动好blazeDS(即启动tomcat,在[tomcat]/webapps目录下产生一个blazeds文件夹(三个war包产生一个blazeds文件夹));
在myeclipse8.5新建一个web Project工程,工程名为webSpring;
把此工程加入blazeDS支持(即用blazeds下的WEB-INF文件夹替换掉web工程下的WEB-INF文件夹);
加入spring支持(把spring相关的jar包拷贝到webSpring/WebRoot/WEB-INF/lib目录下即可)。
二、 1. 在javaWeb工程webSpring的str目录下分别新建一下两个包:
cn.xuediit.myFactory、cn.xuediit.myService;
2. 在cn.xuediit.myFctory包下新建两个类:FlexFactoryImpl.java和SpringFactoryInstance.java
(1). FlexFactoryImpl.java:
package cn.xuediit.myFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import flex.messaging.FactoryInstance;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
public class FlexFactoryImpl implements FlexFactory {
private Log log = LogFactory.getLog(getClass());
/*override interface method*/
public void initialize(String id, ConfigMap configMap) {
System.out.println("1---flex工厂实现类重写的方法initialize");
}
/*override interface method*/
public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {
System.out.println("2---flex工厂实现类重写的方法createFactoryInstance");
log.info("Create FactoryInstance.");
SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties);
instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));
return instance;
}
/*override interface method*/
public Object lookup(FactoryInstance instanceInfo) {
System.out.println("4---flex工厂实现类重写的方法lookup");
log.info("Lookup service object.");
return instanceInfo.lookup();
}
}
(2).SpringFactoryInstance.java
package cn.xuediit.myFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import flex.messaging.FactoryInstance;
import flex.messaging.FlexContext;
import flex.messaging.FlexFactory;
import flex.messaging.config.ConfigMap;
import flex.messaging.services.ServiceException;
public class SpringFactoryInstance extends FactoryInstance {
private Log log = LogFactory.getLog(getClass());
SpringFactoryInstance(FlexFactory factory, String id, ConfigMap properties) {
super(factory, id, properties);
}
public Object lookup() {
System.out.println("3---spring工厂类的方法lookup");
ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(FlexContext.getServletConfig().getServletContext());
String beanName = getSource();
try {
log.info("Lookup bean from Spring ApplicationContext: " + beanName);
return appContext.getBean(beanName);
} catch (NoSuchBeanDefinitionException nex) {
ServiceException e = new ServiceException();
String msg = "Spring service named '" + beanName + "' does not exist.";
e.setMessage(msg);
e.setRootCause(nex);
e.setDetails(msg);
e.setCode("Server.Processing");
throw e;
} catch (BeansException bex) {
ServiceException e = new ServiceException();
String msg = "Unable to create Spring service named '" + beanName + "'.";
e.setMessage(msg);
e.setRootCause(bex);
e.setDetails(msg);
e.setCode("Server.Processing");
throw e;
} catch (Exception ex) {
ServiceException e = new ServiceException();
String msg = "Unexpected exception when trying to create Spring service named '" + beanName + "'.";
e.setMessage(msg);
e.setRootCause(ex);
e.setDetails(msg);
e.setCode("Server.Processing");
throw e;
}
}
}
3. 在cn.xuediit.myService包下新建两个类:FService.java和FServicesImpl.java
(1). FService.java
package cn.xuediit.myService;
public interface FService {
public String sayHello(String name);
}
(2). FServicesImpl.java
package cn.xuediit.myService;
public class FServicesImpl implements FService {
public String sayHello(String name) {
System.out.println("5---服务层实现类(本质上的与flex交互的类)");
return "我是服务层的服务实现类==" + name;
}
}
三、 1、 在javaWeb工程webSpring下,在文件webSpring/WebRoot/WEB-INF/web.xml的web-app标签下添加子节点:
listener
listener-class
org.springframework.web.context.ContextLoaderListener
/listener-class
/listener
2、 在javaWeb工程webSpring下,在webSpring/WebRoot/WEB-INF目录下新建一个文件:applicationContext.xml
?xml version="1.0" encoding="UTF-8"?
beans xmlns=""
xmlns:xsi=""
xmlns:tx=""
xsi:schemaLocation="
"
bean id="fServiceImplBeanID" class="cn.xuediit.myService.FServicesImpl"/bean
/beans
四、 1、 在javaWeb工程webSpring下,在WebRoot/WEB-INF/flex/remoting-config.xml文件中的service标签下添加:
destination id="destinationID"
properties
factoryflexFactoryImplID/factory
sourcefServiceImplBeanID/source
scopeapplication/scope
/properties
/destination
2、 在javaWeb工程webSpring下,在WebRoot/WEB-INF/flex/services-config.xml文件中的services-config标签下添加:
factories
factory id="flexFactoryImplID" class="cn.xuediit.myFactory.FlexFactoryImpl"/
/factories
五、 给此javaWeb工程添加tomcat支持,启动tomcat(这个容易就不说了)。
六、 在flashBuilder下新建一个基于blazeDS的flex项目(以webSpring为后台工程),工程名为webFb;
webFb.mxml:
?xml version="1.0" encoding="utf-8"?
s:Application xmlns:fx=""
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
minWidth="500" minHeight="200"
fx:Script
![CDATA[
import mx.core.Application;
import mx.rpc.events.FaultEvent;
import mx.collections.ArrayCollection;
import mx.rpc.remoting.mxml.RemoteObject;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
public function submit(name:String):void{
var remote:RemoteObject = new RemoteObject();
remote.destination = "destinationID";
remote.endpoint = "";
remote.addEventListener(ResultEvent.RESULT, myResult);
remote.addEventListener(FaultEvent.FAULT,fault);
remote.sayHello(name);
}
private function myResult(evt:ResultEvent):void{
Alert.show(evt.result.toString());
}
private function fault(evt:FaultEvent):void{
Alert.show(evt.fault.message);
}
]]
/fx:Script
s:Button x="240" y="11" label="要发送到" click="submit(nameTxt.text)"/
s:Label x="16" y="11" text="姓名"/
s:TextInput id="nameTxt" x="100" y="100"/
/s:Application
flex连接java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于flex怎么使用、flex连接java的信息别忘了在本站进行查找喔。
发布于:2022-11-26,除非注明,否则均为
原创文章,转载请注明出处。