JS get URL parameters and URL encoding, decoding

Source: Internet
Author: User

The complete URL consists of these parts: Scheme://host:port/path?query#fragment, the various parts are as follows:

Window.location.href: The way to get the full URL: scheme://host:port/path?query#fragment

Window.location.protocol: Get Rul protocol scheme

Window.location.host: Get Host

Window.location.port: Get port number

Window.location.pathname: Get URL path

Window.location.search: Get the parameter query section, and note what is returned here? query

Window.location.hash: Gets the anchor point, #fragment

In JS you can use Escape (), Encodeurl (), encodeURIComponent (), and three methods have some symbols that will not be encoded:

Escape (): @ */+

Encodeurl ():! @ # $& * () =:/;? +


encodeURIComponent ():! * ( ) ‘

Urldecoder.decode ("Chinese", "UTF-8") can be used on the Java side to decode

However, since the encoding has been decoded by using request.getparameter () to get the parameters, it is generally only used in JS


encodeURIComponent ("Chinese");

Use Request.getparameter () directly on the Java side to get back to Chinese.

If you want to use Urldecoder.decode ("Chinese", "UTF-8") on the Java side, decoding can also be encoded in JS two times, namely:

encodeURIComponent (encodeURIComponent ("Chinese"));

If you do not encode two times, the Java side through the Decode method will be garbled.

JS get URL parameters and URL encoding, decoding

JS get URL parameters and URL encoding, decoding

Related Article

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.