Flex开发中使用Ant编译.mxml成.swf后,在.swf里使用Session的解决方法
http://iamin.blogdriver.com/iamin/1176113.html
Flex Remote Object中直接使用HttpSession的方法在Flex Samples里有Session的操作使用例子:
http://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了。