论坛首页 Web前端技术论坛

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

浏览 4881 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-10-14  

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的处理

http://livedocs.macromedia.com/flex/15/flex_docs_en/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flex_Documentation&file=00002247.htm

Working with session data
A Java object that you call using the <remoteobject></remoteobject>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了。



论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics