Java method for intercepting URL parameters _java

Source: Internet
Author: User
Tags lzf stringbuffer

Talk less, and went straight to the key code.

The specific code looks like this:

/** * Remove the path in the URL, leaving the request parameter part * @param strurl URL address * @return URL request parameter part * @author LZF/private static String Truncateurlpage (String strURL)
{String strallparam=null;
String[] Arrsplit=null;
Strurl=strurl.trim (). toLowerCase ();
Arrsplit=strurl.split ("[?]"); if (Strurl.length () >1) {if (arrsplit.length>1) {for (int i=1;i<arrsplit.length;i++) {Strallparam = ArrSplit[i]
; 
}} return Strallparam; /** * resolves the key values in the URL parameter to * such as "index.jsp?" Action=del&id=123 ", parse out action:del,id:123 into map * @param URL url address * @return URL request parameter part * @author LZF/public static Ma P<string, string> urlsplit (String URL) {map<string, string> maprequest = new hashmap<string, String> ()
;
String[] Arrsplit=null;
String strurlparam=truncateurlpage (URL);
if (strurlparam==null) {return maprequest;} arrsplit=strurlparam.split ("[;]"); 
for (String strsplit:arrsplit) {string[] arrsplitequal=null;
Arrsplitequal= strsplit.split ("[=]"); Parse out the key value if (arrsplitequal.length>1) {//parse Maprequest.put correctly (arrsplitequAl[0], arrsplitequal[1]); 
}else{if (arrsplitequal[0]!= "") {//Only parameter has no value, does not join Maprequest.put (arrsplitequal[0], ""); 
}} return maprequest; }

Ps:java intercept the value in the URL

Map<string, object> urlsplit (String data) {
StringBuffer strbuf = new StringBuffer ();
StringBuffer strbuf2 = new StringBuffer ();
map<string,object> map = new hashmap<string,object> ();
for (int i =0;i<data.length (); i++) {
if (data.substring (i,i+1). Equals ("=")) {for
(int n=i+1;n< Data.length (); n++) {
if (data.substring (n,n+1). Equals ("&") | | n ==data.length ()-1) {
map.put ( Strbuf.tostring (), strbuf2);
Strbuf =new StringBuffer ("");
Strbuf2 =new StringBuffer ("");
I=n;
break;
Strbuf2.append (data.substring (n,n+1));
}
Continue;
}
Strbuf.append (data.substring (i,i+1));
}
return map;
}

The above is a small set up to introduce the Java method of intercepting URL parameters and Java interception URL value method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.