天天看点

Flex开发中使用Ant编译.mxml成.swf后,在.swf里使用Session的解决方法

flex开发中使用ant编译.mxml成.swf后,在.swf里使用session的解决方法

<a href="http://iamin.blogdriver.com/iamin/1176113.html">http://iamin.blogdriver.com/iamin/1176113.html</a>

flex remote object中直接使用httpsession的方法在flex samples里有session的操作使用例子:

<a href="http://localhost:8080/samples/explorer/misc/serversessiondemo.mxml">http://localhost:8080/samples/explorer/misc/serversessiondemo.mxml</a>

但是,使用mxmlc编译.mxml成.swf后,在.swf里是没有办法使用session的

解决办法:可以通过remoteobject的通讯方式来进行session的处理

<a href="http://livedocs.macromedia.com/flex/15/flex_docs_en/wwhelp/wwhimpl/common/html/wwhelp.htm?context=flex_documentation&amp;file=00002247.htm">http://livedocs.macromedia.com/flex/15/flex_docs_en/wwhelp/wwhimpl/common/html/wwhelp.htm?context=flex_documentation&amp;file=00002247.htm</a>

working with session data

a java object that you call using the tag has access to request, response, and servlet data. from within a java object, you can call the following methods:

method description

flashgateway.gateway.gethttprequest()

returns the httpservletrequest object for the current request. macromedia recommends that you access session data and other request data through the gethttprequest() method.

flashgateway.gateway.gethttpresponse()

returns the httpservletresponse object for the current request.

flashgateway.gateway.getservletconfig()

returns the servletconfig object for the calling servlet.

to compile calls with these methods in their classes, you must have the web-inf/lib/flashgateway.jar file in your classpath.

the following example shows code in a java class for accessing a session attribute:

string fooattrib = (string)flashgateway.gateway.gethttprequest().getsession().

getattribute("attr1");

这样,.mxml文件经过编译成.swf后,照样可以进行使用session了。