首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

httpService URL 硬编码有关问题

2012-03-29 
httpService URL 硬编码问题怎么样避免httpService URL 硬编码问题XML codemx:HTTPService idhelloWorl

httpService URL 硬编码问题
怎么样避免httpService URL 硬编码问题

XML code
    <mx:HTTPService id="helloWorldServiceRequest" method="get" [color=#FF0000]url="http://192.168.1.102:8080/helloWorldServlet"[/color]  result="httpResultHandler(event)" fault="httpErrorHandler(event)" > </mx:HTTPService>

很明显,上面这样写 把URL地址写死了。倘若flex编译后的flash文件和helloWorldServlet一直部署在
192.168.1.102上,那很OK. 但是 当把2者部署到其他的服务器上 那不就挂了!
   
我尝试 用相对路径去 写这个servlet的地址。如:
XML code
    <mx:HTTPService id="helloWorldServiceRequest" method="get" [color=#800080]url="helloWorldServlet"  result="httpResultHandler(event)"[/color] fault="httpErrorHandler(event)" > </mx:HTTPService>
但是不行!

所以 ,请教大家 有什么好办法避免硬编码问题。

[解决办法]
当然是可以相对路径的,如果我没记错,相对的应该是嵌这个SWF的页面(HTML,JSP之类)
[解决办法]
相对路径是可以的,但你要确保你运行代码时,浏览器上访问的ip是192.168.1.102而不是在本地测试。

Server端能够得到这个值http://192.168.1.102:8080/helloWorldServlet/,
或者传递这个/helloWorldServlet/

然后在HTML载入swf的地方,把这个当参数传递到flex里面
AC_FL_RunContent(
'src', 'xxx.swf',
'FlashVars', 'webContent="http://192.168.1.102:8080/helloWorldServlet/"',
'width', '100%',
'height', '100%',
'align', 'middle',
'id', 'mainUI',
'quality', 'high',
'bgcolor', '#869ca7',
'name', 'mainUI',
'allowScriptAccess','always',
'type', 'application/x-shockwave-flash',
'pluginspage', 'http://www.adobe.com/go/getflashplayer'
);

注意'FlashVars', 'webContent="http://192.168.1.102/helloWorldServlet/"',
webContent对应的值不是写死的,可以从server端传递过来。

然后在flex里面这样接受:
var parameters:Object = Application.application.parameters;
var webContent:String = parameters.webContent;
如果做的好的话,可以建立一个资源类,把这个值存在静态属性里面,以后需要的地方,从这个资源类里面获取。
[解决办法]
完全可以使用相对路径

相对于项目

热点排行