Flex開發中使用Ant編譯.mxml成.swf後,在.swf裏使用Session的解決方法
Flex開發中使用Ant編譯.mxml成.swf後,在.swf裏使用Session的解決方法
https://iamin.blogdriver.com/iamin/1176113.html
Flex Remote Object中直接使用HttpSession的方法在Flex Samples裏有Session的操作使用例子:
https://localhost:8080/samples/explorer/misc/ServerSessionDemo.mxml
但是,使用mxmlc編譯.mxml成.swf後,在.swf裏是沒有辦法使用Session的
解決辦法:可以通過RemoteObject的通訊方式來進行Session的處理
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了。
最後更新:2017-04-02 00:00:27