Flash Security policy configuration (1)

Source: Internet
Author: User
Tags addchild

When flash communicates with JSP recently, flash cannot send messages to JSP. It was really depressing. I read the official document and found a simple solution. The first official solution is user management control. This global solution solves the problem of communication between flash and JSP.

 

 

The solution is as follows:

Step 1

Find the path directory in the system:

C:/Windows/system32/macromed/flash/flashplayertrust

 

FlashplayertrustThis folder is a trusted area.

 

We can see several files with suffixes, XXX. cfg. To solve the communication problem between flash and JSP, I create a text named Dev in this directory:

 

 

Step 2:

Create the dev.txt text and write the directory where the flash file is located. I put the directory in the test folder of the idisk, and then changed the suffix to the cfg file.

Dev. cfg file

 

 

File directory:

 

 

 

After preparation, test our file:

Prepare a JSP file, as shown below, and accept the two messages returned by the client.

<% @ Page Language = "Java" pageencoding = "UTF-8" <br/> %> <% string username = request. getparameter ("username"); <br/> string userpwd = request. getparameter ("userpwd"); <br/> out. println ("MSG =" + username); <br/>%> </P> <p>

 

 

Prepare the client: perform a simple test.

 Package <br/> {<br/> Import flash.net. urlloader; <br/> Import flash.net. URLRequest; <br/> Import flash. events. *; <br/> Import flash.net. urlvariables; <br/> Import flash.net. urlloaderdataformat; <br/> Import flash.net. *; <br/> public class connect extends eventdispatcher <br/> {<br/> // URL of the connection <br/> Public static const myurl: String = "http: // localhost: 8080/flash2/receive. JSP "; <br/> Public Function connect () <br/>{</P> <p >}< br/> Public Function sendmessage (para: urlvariables, myurl: string): void <br/>{// set the variable for sending data </P> <p> // set the method for sending data <br/> var request: URLRequest = new URLRequest (); <br/> request. url = myurl; <br/> request. method = urlrequestmethod. post; // method of sending post <br/> request. data = para; </P> <p> // send data <br/> var Loader: urlloader = new urlloader (); <br/> loader. dataformat = urlloaderdataformat. variables; // format of data transmission <br/> loader. addeventlistener (event. complete, completehandler); <br/> loader. addeventlistener (ioerrorevent. io_error, iohandler); <br/> loader. addeventlistener (securityerrorevent. security_error, securityhandler); <br/> loader. load (request); <br/>}< br/> private function completehandler (Event: Event): void <br/>{< br/> var Loader: urlloader=urlloader(event.tar get ); <br/> trace (loader. data); <br/> trace (loader. data. MSG); <br/>}< br/> private function iohandler (Event: ioerrorevent): void <br/>{< br/> trace ("wrong "); <br/>}< br/> private function securityhandler (Event: securityerrorevent): void <br/>{< br/> trace ("wrong2 "); <br/>}< br/>}

 

Package <br/> {<br/> Import flash. display. sprite; <br/> Import flash. events. *; <br/> Import flash. text. *; <br/> Import flash. display. simplebutton; <br/> Import FL. controls. button; <br/> Import flash.net. *; <br/> public class main extends sprite <br/>{< br/> private var con: connect; <br/> private var Username: textfield; <br/> private var PWD: textfield; <br/> public function main () <br/> {<br/> con = new connect (); </P> <p> Init (); <br/>}</P> <p> private function Init (): void <br/> {</P> <p> username = new textfield (); <br/> addchild (username); <br/> username. width = 200; <br/> username. height = 20; <br/> username. X = stage. stagewidth/2; <br/> username. y = stage. stageheight/2; <br/> username. type = textfieldtype. input; // Input Method <br/> username. border = true; // border <br/> username. background = true; </P> <p> Pwd = new textfield (); <br/> addchild (PWD); <br/> pwd. width = 200; <br/> pwd. height = 20; <br/> pwd. X = stage. stagewidth/2; <br/> pwd. y = stage. stageheight/2 + 22; <br/> pwd. type = textfieldtype. input; // input mode <br/> pwd. border = true; // border <br/> pwd. background = true; </P> <p> var BTN: button = new button (); <br/> addchild (BTN); <br/> BTN. width = 40; <br/> BTN. height = 20; <br/> BTN. label = "send"; <br/> BTN. X = stage. stagewidth/2; <br/> BTN. y = stage. stageheight/2 + 50; <br/> B Tn. addeventlistener (mouseevent. click, sendhander); </P> <p >}< br/> private function sendhander (E: mouseevent): void <br/>{< br/> If (username. text! = "" & PWD. Text! = "") <Br/>{< br/> trace ("Send OK"); <br/> var para: urlvariables = new urlvariables (); <br/> para. username = username. text; <br/> para. userpwd = PWD. text; <br/> con. sendmessage (para, connect. myurl); <br/>}else <br/>{< br/> trace ("Empty message cannot be sent "); <br/>}< br/>}

 

In this way, you can simply send the information, because the program can still be improved here, lazy, mainly describes the security configuration problem.

 

 

 

In the program, we should be careful

Public static const myurl: String = "http: // localhost: 8080/flash2/receive. jsp ";

 

Our SWF file is not in the Tomcat directory, as long as it is in another disk. During local testing

C:/Windows/system32/macromed/flash/flashplayertrust

 

Add the directory where the SWF file is located to solve this simple problem. Now you can communicate.

 

 

Note: problems caused by the firewall may sometimes intercept messages, so it is no longer necessary to close the test. Of course, this is only a special case

 

 

 

 

 

 

 

 

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.