Example of sending a string from the flex end to the server to generate a file (method for obtaining a request object in flex)

Source: Internet
Author: User

Core code of flex:
<Mx: remoteobject id = "service" Destination = "studentservice" fault = "{failure ();}" concurrency = "single"> <br/> <mx: method Name = "wrtietofile" result = "{writefileresult (event)}"/> <br/> </MX: remoteobject> </P> <p> <mx: SCRIPT> </P> <p> <! -- [CDATA [</P> <p> private function failure (): void {<br/> alert. show ("failed to load data"); <br/>}</P> <p> Public Function writefile (): void {<br/> service. wrtietofile (_ textarea. text); <br/>}</P> <p> Public Function writefileresult (Event: resultevent): void {<br/> alert. show (event. result. tostring (); <br/>}</P> <p>] --> </P> <p> </MX: SCRIPT> </P> <p> <mx: button x = "406" Y = "176" label = "Write File" Click = "{writefile ();} "/> </P> <p> <mx: textarea x = "219" Y = "214" width = "349" Height = "160" id = "_ textarea"/> </P> <p>

 

Java server core code:

 @ Suppresswarnings ("deprecation") <br/> Public String wrtietofile (string context) {<br/> string filepath = ""; </P> <p> try <br/> {<br/> context = new string (context. getbytes ("UTF-8"); <br/> httpservletrequest request = flexcontext. gethttprequest (); <br/> string Path = request. getrealpath ("/"); <br/> filepath = path + "workflow. XML "; <br/> filewriter fw = new filewriter (filepath); <br/> bufferedwriter BW = new bufferedwriter (FW); <br/> BW. write (context); <br/> BW. close (); <br/>}< br/> catch (exception ex) {<br/> ex. printstacktrace (); <br/>}< br/> return filepath; <br/>}< br/>

Note: encoding of character sets

 

 

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.