天天看點

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了。