Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
Flex与Servlet通讯(中);

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

在上一篇文章中,我使用<mx:model>与servlet通讯,但是网上的例子大部分用<mx:httpservice>。但是我用以下方式的时候,就出现错误了.
<mx:HTTPService id="ServletService1" url="servlet/XMLFacadeServlet"   >
        <mx:request/>
               </mx:HTTPService>

于是我就查看web.xml,改动了好几处,还是出现错误,看看自带的sample,代码还是差不多一样了阿。
试了好久,也没弄好。于是就搜索包含文z字employees.jsp(sample的url是这个),发现这个文件flex-config.xml
,知道就是他了,打开,有这么一段

    <http-service-proxy>
    ..........................
<whitelist>
            <!-- whitelist config for unnamed services -->
            <unnamed>
              <url>http://{localserver}/*</url>
                <url>https://{localserver}/*</url
..............................................
</unnamed>

            <!-- whitelist config for named services -->
            <named>
....................
<service name="SampleEmployeeSrv">
                    <url>{context.root}/explorer/data/employees.jsp</url>
                    <use-custom-authentication>true</use-custom-authentication>
                </service>
................................................
再看在flex目录下的 flex-config.xml文件
<whitelist>
            <!-- whitelist config for unnamed services -->
            <unnamed>
                <url></url>
                <!--
                For security, the whitelist is locked down by default.
                Uncomment the first two urls below to enable access to all URLs,
                or the last two urls to enable access to the local server,
                or add above the individual URLs you wish to access.
                <url>http://*</url>
                <url>https://*</url>
                <url>http://{localserver}/*</url>
                <url>https://{localserver}/*</url>
                -->
            </unnamed>
            <!-- whitelist config for named http services -->
            <!-- <named> -->
                <!-- define an http service which may be referenced by name from mxml -->
                <!-- <service name="service"> -->
                    <!-- enables use of custom fault code on the client for handling authentication failures -->
                    <!-- <use-custom-authentication>false</use-custom-authentication> -->
                    <!-- actual url to use when accessing the named http service -->
                    <!-- <url>http://localhost:8100/flex/servicename</url> -->
                    <!-- user-name and password to use when accessing this http service -->
                    <!-- <run-as user="user" password="pwd"/> -->
                    <!-- Adds the service's url to the unnamed whitelist.  If false, these can never be used unnamed -->
                    <!-- This should be set to false if using web application security with this named service -->
                    <!-- <allow-unnamed-access>true</allow-unnamed-access> -->
                <!-- </service> -->
            <!-- </named> -->
                          </whitelist>
于是,我把
<url>http://*</url>
                <url>https://*</url>
                <url>http://{localserver}/*</url>
                <url>https://{localserver}/*</url>
这段的注释符去掉就可以了。
 还有一种访问servlet的方法就是通过named来的,如在上面<named>...</named>加上

                <service name="ServletService">
                    <url>{context.root}/servlet/XMLFacadeServlet</url>
                    <use-custom-authentication>true</use-custom-authentication>
                </service>
mxml这样使用:
<mx:HTTPService id="ServletService1" serviceName="ServletService">

mx:HTTPService 需要一个send操作才能执行发送GET或POST命令以获得数据,如:
        <mx:Button label="Get Employee List" click="employeeSrv.send();"/>
修改flex-config.xml后要重起tomcat的,如果你修改后flex-config.xml存在问题(如:把named写成name),
访问mxml的时候就会出现 url is not available 这个错误了。

 




相关文章

相关软件