首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

(转) Flex跟jsp整合实践

2012-10-29 
(转) Flex和jsp整合实践!--[endif]--!--[if gte mso 9]xml w:WordDocumentw:ViewNormal/w:View

(转) Flex和jsp整合实践


<!-- [endif]-->

<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument></xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles></xml><![endif]--><!-- [if gte mso 10]><mce:style><! /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.0pt;font-family:"Times New Roman";mso-ansi-language:#0400;mso-fareast-language:#0400;mso-bidi-language:#0400;}--><!-- [endif]-->

<!-- [if !supportLists]-->(2)??? <!-- [endif]-->构建项目,把生成的 .swf 和 .js 文件拷贝到 tomcat 的应用程序发布目录中。

?

2 、 jsp 编码部分

(1) 新建 xmltree.jsp ,主要是根据用户的部门 id 从数据库中获得通讯簿记录,并形成 xml 文件供 flex httpservice 组件调用,具体实现参考源文件。

(2) 新建 flexSend.jsp ,实现发送页面,需要注意的代码有如下几处:

第 6-7 行:

String xmldata=request.getRequestURL().toString();// 取得请求 url

?????? xmldata=xmldata.substring(0,xmldata.lastIndexOf("/"))+"/xmltree.jsp";

由于 ajax 跨域访问的问题, flex 的 httpservice 组件在访问 web 页面时,不能把 url 写死,比如: http://www.handtimes.com/xxxxx 。因为如果 dns 不可用,我们常常会通过 ip 地址访问,这样的话, ip 地址和原来的域名不一样,就导致跨域访问问题 ,ajax 请求收不到 xml 数据,通讯簿树显示不出来。

?

第 60 行:

var flashvars =
{url:"<%=xmldata%>",unit:"<%=unit%>",mark:"<%=strName%>",maxwords:"<%=i_nameLength%>"};

jsp 中的 session 值,我们只能通过 flashvars 参数传递给 swf ,因此在这里我们给 flashvars 参数写入了许多 jsp 变量。

?

第 81-87 行:

function swfsubmit(selectedNo,attachedNo,content){

?????? dataform.AddDest.value=selectedNo+attachedNo;????????????????????????????????? dataform.content.value=content;

?????? if(confirm(" 确定要进行发送吗? ")){

??????????????????????????? doPost();

?????? }

}

?

实际上这个 js 函数当 swf 中的“确定”按钮被点击时调用。在这里我们仅把 flex 控件值做了一个复制,复制到 html 表单控件中,然后利用表单进行提交。

?

(3) 短信发送页面。没有什么特别的,具体实现参考源文件。

ie7.0和firefox下测试通过。

热点排行