For beginners, Flex is used to write an example of interaction between flex (through urlloader) and the background to solve noon garbled processing:
This is the code for Flex. jsp:
<%... @ Page contenttype = "text/html; charset = UTF-8" %>
<%...
String USR = java.net. urldecoder. Decode (request. getparameter ("user"), "UTF-8 ");
System. Out. println ("Get input parameter:" + USR );
String psw = java.net. urldecoder. Decode (request. getparameter ("psw"), "UTF-8 ");
System. Out. println ("Get input parameter:" + psw );
%>
<% = USR %> + <% = psw %>
This is the code of login. mxml:
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"
Layout = "absolute" fontsize = "12" xmlns: Local = "*">
<Mx: TraceTarget/>
<Mx: style>
. Lab {
Fontweight: "bold ";
/* Color: # ff0000 ;*/
Fontsize: 15;
}
</MX: style>
<Mx: SCRIPT>
<! [CDATA [
// Encode the parameters submitted to the backend
Private function httpencoding (Param: string): String {
Return encodeuricomponent (PARAM );
}
Private function dologin (): void {
// Trace ("focusenabled:" + loading. focusenabled );
// This. focusmanager. setfocus (User );
VaR URL: String = "http: // localhost: 8600/flex. jsp ";
VaR Params: urlvariables = new urlvariables ();
// This user. psw is the parameter user passed in to the background. jsp uses request. getparameter ("user") to obtain
Params. User = httpencoding (user. Text );
Params. psw = psw. text;
VaR Loader: urlloader = new urlloader ();
This. configureeventlisteners (loader );
// You can leave it unspecified because the default value is text.
Loader. dataformat = urlloaderdataformat. text;
VaR request: URLRequest = new URLRequest (URL );
Request. Data = Params;
Try {
Loader. Load (request );
} Catch (error: Error ){
Trace (error. Message );
}
}
Private function configureeventlisteners (Dispatcher: ieventdispatcher): void {
Dispatcher. addeventlistener (event. Complete, completehandler );
Dispatcher. addeventlistener (event. Open, openhandler );
Dispatcher. addeventlistener (progressevent. Progress, progresshandler );
Dispatcher. addeventlistener (securityerrorevent. security_error, securityerrorhandler );
Dispatcher. addeventlistener (httpstatusevent. http_status, httpstatushandler );
Dispatcher. addeventlistener (ioerrorevent. io_error, ioerrorhandler );
}
Private function completehandler (Event: Event): void {
VaR Loader: urlloader = urlloader(event.tar get );
Trace ("-- complete..." using event.tar get. data );
// Var dataxml: xml = xml(event.tar get. data );
// Trace (dataxml. toxmlstring ());
Btn_btn.enabled = true;
}
Private function openhandler (Event: Event): void {
Trace ("openhandler:" + Event );
// This. focusmanager. setfocus (loading );
Btn_btn.enabled = false;
}
Private function progresshandler (Event: progressevent): void {
Trace ("progresshandler loaded:" + event. bytesloaded + "Total:" + event. bytestotal );
}
Private function securityerrorhandler (Event: securityerrorevent): void {
Trace ("securityerrorhandler:" + Event );
}
Private function httpstatushandler (Event: httpstatusevent): void {
Trace ("httpstatushandler:" + Event );
}
Private function ioerrorhandler (Event: ioerrorevent): void {
Trace ("ioerrorhandler:" + Event );
}
]>
</MX: SCRIPT>
<Mx: panel title = "welcome to the WAP management system: "width =" 307 "Height =" 189 "layout =" absolute "verticalalign =" TOP "horizontalcenter ="-10.5 "verticalcenter ="-9 ">
<Mx: Label x = "32" Y = "25" text = "Logon password:" width = "59"/>
<Mx: textinput id = "user" x = "99" y =" 23 "width =" 147 "/>
<Mx: Label x = "32" Y = "53" text = "Logon password:" width = "59"/>
<Mx: textinput id = "psw" x = "99" Y = "51" displayaspassword = "true" width = "147"/>
<Mx: controlbar alpha = "1">
<Mx: button id = "btn_btn" x = "58" Y = "92" label = "Confirm" Click = "This. dologin ();"/>
<Mx: button x = "162" Y = "92" label = "Remove"/>
<Mx: Label x = "0" Y = "129" text = "powered by Keren" textalign = "right"/>
</MX: controlbar>
</MX: Panel>
</MX: Application>