Java and flex Study Notes (13) -- parse parameters passed in the address bar in flex

Source: Internet
Author: User


Recently, I made a mail activation function. I did not expect that the more knowledge points I need to know, the more logical judgments I have, and the more I can think. We are now sharing the problem of parsing the address bar parameters.


Since the default page encapsulated by Flex is an HTML page, what is different from JSP is that the parameter is passed after "#", while JSP is in "?" Later, so we have to figure this out.


To parse parameters, you first need to obtain the Link parameter chain (namely the parameter pair after "#") in the address bar. There are many methods, such as calling the externalinterface of JavaScript. the call () method is obtained by using the flex static class browsermanager. The Code is as follows:

 

/*** Get the parameter chain in the address bar **/Public Function getallparams (): String {var BM: ibrowsermanager = browsermanager. getinstance (); BM. init (); Return BM. fragment}

This method returns the address bar parameter pair.


The following code splits the parameter pairs and stores them in an object:


/*** Receive and parse URL Information in the browser's address bar **/Public functiongetparams (): object {var Params: Object ={}; var query: String = getallparams (); if (query) {var pairs: array = query. split ("&"); For (var I: uint = 0; I <pairs. length; I ++) {var pos: Int = pairs [I]. indexof ("="); If (Pos! =-1) {var argname: String = pairs [I]. substring (0, POS); VaR value: String = pairs [I]. substring (Pos + 1); Params [argname] = value ;}} return Params ;}

 

This method returns an object. If the parameter chain is not empty, the value is as follows:


    Var obj:Object= getParams();    Var email:String=obj.email;

Then you can add your own business logic.


For example, if the test page does not contain parameters:




Business judgment when parameters are available:




There are a lot more. I will not list them one by one, but I just want to make an axe in front of Daniel.


Original article, reproduced please indicate the source: http://www.dianfusoft.com/



 

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.