If we only need to use a part of the Flex function, such as the player function, we can separately embed the flex page into the JSP page. To implement this function, you need to download a project and overwrite it in the root directory of the server. You can download flexmodule_j2ee.zip.
Create a web project under eclipse, decompress the downloaded project, and overwrite the content in the webtier folder to the root directory of the server, as shown in my own:
Note that you need to add the jar packages in the Lib folder and jars folder to the class path, so that the integration is complete.
Create a new Flex mxml file playvideo. mxml and put it under webcontent. The Code is as follows:
<?xmlversion="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"creationComplete="init()"><mx:Script><![CDATA[ import mx.controls.Alert; private var rtmpURL:String="rtmp://localhost/oflaDemo"; private var nc:NetConnection=new NetConnection(); private var playerVideo:Video=new Video(); [Bindable] private var stream:NetStream; private function init():void{ playerVideo.width = 500; playerVideo.height = 400; connect(); } private function connect():void{ nc.addEventListener(NetStatusEvent.NET_STATUS,netStatus); nc.connect(rtmpURL); } private function netStatus(e:NetStatusEvent):void{ trace(e.info.code); if(e.info.code=="NetConnection.Connect.Success"){ stream=new NetStream(nc); playerVideo.attachNetStream(stream); stream.play("chirisyu_ytywn.flv"); container.addChild(playerVideo); } }]]></mx:Script> <mx:UIComponent id="container"></mx:UIComponent></mx:Application>
This file implements the reduced version of the video that was previously played with red5.
Create a new JSP file as follows:
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8 "pageencoding =" UTF-8 "%> <% @ taglib uri =" flextaglib "prefix =" mm "%> <! Doctype HTML public "-// W3C // dtdhtml 4.01 transitional // en" http://www.w3.org/TR/html4/loose.dtd "> <HTML>
It can be seen that what needs to be done to introduce the mxml file into JSP is:
1. Declare and introduce tags, such as <% @ tagliburi ="Flextaglib"Prefix ="Mm"%>. If the Web. xml file is not added
<taglib> <taglib-uri>FlexTagLib</taglib-uri> <taglib-location>/WEB-INF/lib/flex-bootstrap-jsp.jar</taglib-location></taglib>
.
2. Introduce the mxml file in the <mm: mxml/> label, which has some attributes. You can view the API and I will not go into details here.
Okay. Now we can test it. Run the JSP file. If it runs successfully, it indicates that it is successful:
Of course, this mxml file uses the Flex 3 file. If it is changed to flex4, an error will be reported, because the jar package currently in use does not support the flex4 tag, and I wonder if the author will update it.
Original article, reproduced please indicate the source: http://www.dianfusoft.com/