Java and Flex Learning notes---Embed a flex page in a JSP page

Source: Internet
Author: User
Tags cdata

If we only need to use part of the Flex feature, such as the player feature, we can embed the Flex page separately in the JSP page. To implement this feature, you need to download a project and overwrite it in the server root directory. You can download: Flexmodule_j2ee.zip.

Create a new Web project under Eclipse, unzip the project you just downloaded, and then overwrite the contents of the Webtier folder under the server root directory, such as:

Note To add the jar package under the Lib folder and the Jars folder to the Classpath, this is a complete integration.

Then create a new flex Mxml file Playvideo.mxml, put it under WebContent, and the code looks like this:

[HTML]View Plaincopyprint?
  1. <? xmlversionxmlversion="1.0" encoding="Utf-8"?>
  2. <mx:application xmlns:mx="Http://www.adobe.com/2006/mxml" layout="Absolute "
  3. Creationcomplete="init ()">
  4. <mx:script>
  5. <! [cdata[
  6. Import Mx.controls.Alert;
  7. private var rtmpurl:string= "Rtmp://localhost/oflademo";
  8. private var nc:netconnection=new netconnection ();
  9. private var playervideo:video=new Video ();
  10. [Bindable]
  11. private Var Stream:netstream;
  12. Private Function init (): void{
  13. Playervideo.width = 500;
  14. Playervideo.height = 400;
  15. Connect ();
  16. }
  17. Private function Connect (): void{
  18. Nc.addeventlistener (Netstatusevent.net_status,netstatus);
  19. Nc.connect (Rtmpurl);
  20. }
  21. Private Function Netstatus (e:netstatusevent): void{
  22. Trace (E.info.code);
  23. if (e.info.code== "NetConnection.Connect.Success") {
  24. Stream=new NetStream (NC);
  25. Playervideo.attachnetstream (stream);
  26. Stream.play ("chirisyu_ytywn.flv");
  27. Container.addchild (Playervideo);
  28. }
  29. }
  30. ]]>
  31. </mx:script>
  32. <mx:uicomponent id="container"></mx:uicomponent>
  33. </mx:application>



This file implements a reduced version of the video that was previously played with Red5.

Then create a new JSP file, as follows:

[HTML]View Plaincopyprint?
  1. <%@ page language= "java"contenttype= "text/html; charset=UTF-8 "
  2. pageencoding="UTF-8"%>
  3. <% @taglib uri= "flextaglib"prefix= "mm"%>
  4. <! DOCTYPE HTML PUBLIC "-//w3c//dtdhtml 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <Meta http-equiv= "Content-type"content= "text/html; charset=UTF-8 ">
  8. <title> Test </title>
  9. <style type="Text/css">
  10. #mess {
  11. Position:absolute;
  12. left:250px;
  13. top:25px;
  14. font-size:22px;
  15. }
  16. #video {
  17. Position:absolute;
  18. left:250px;
  19. top:70px;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="mess">
  25. Here is the test video:
  26. </div>
  27. <div id="video">
  28. <mm:mxml source= "Playvideo.mxml"width= "height=" >
  29. </mm:mxml>
  30. </div>
  31. </body>
  32. </html>



You can see that what you need to do to introduce an mxml file into a JSP is:

1. Declare the introduction of tags, such as <% @tagliburi ="Flextaglib"prefix="mm"%>. If the Web. xml file is not added

[HTML]View Plaincopyprint?
    1. <taglib>
    2. <taglib-uri>flextaglib</taglib-uri>
    3. <taglib-location>/web-inf/lib/flex-bootstrap-jsp.jar</taglib-location >
    4. </taglib>


, you will get an error.

2. In the <mm:mxml/> tag to introduce the Mxml file, there are some properties, you can view the API, I will not repeat here.

OK, so that you can test, run the JSP file, if successful run proves successful:

Of course, this mxml uses a Flex 3 file, if replaced by FLEX4 will be an error, because the current use of the jar package does not support Flex4 tags, do not know whether the author will update.

original articles, reproduced please specify the source: http://www.it161.com/article/webDetail?articleid=140112111941

For more original content, please visit: http://www.it161.com/

Java and Flex Learning notes---Embed a flex page in a JSP page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.