URL Passing Special Symbols

  • Last update:December 30, 2021
  • I. Description

    Some symbols cannot be passed directly in the URL, such as symbols such as'+','%','&', etc. How to implement these symbols if you want to pass these symbols in the URL?

    II. Solution

    1. Direct input in the browser

    1) Solution

    By converting these special symbols into hexadecimal.

    2) Commonly used special symbols and their codes

    • +: The + sign in the URL represents a space and its encoding is %2B

    • Space: Spaces in the URL can be + sign or encoded %20

    • /: Separate directories and subdirectories, the encoding is %2F

    • ?: Separate the actual URL and the parameter and its encoding is %3F

    • %: Specify a special character whose code is %25

    • #: Indicates that the bookmark code is %23

    • &: The & in the URL represents the separator between the specified parameters and its encoding is %26

    • =: The = in the URL represents the value of the specified parameter and its encoding is %3D

    Note: In the URL, the encoding of "+" is %2B. Except for the normal display when spliced with the encoding %25 of "%", all other splicings are displayed as spaces by default. To display normally, you need to add " The code of +" can be changed to %252B.

    3) Example

    If the string "this%is#te=st&o k?+/" is passed to test.cpt as the value of the parameter t, the URL is:test.cpt&t=this%25is%23te%3Dst%26o%20k%3F%2B%2Fortest.cpt&t=this%25is%23te%3Dst%26o+k%3F%2B%2F(Space can be replaced by %20 or +)

    For example, fill=$tin a cell in test.cpt,Pagination Preview,add the above URL after the URL, the effect is as follows:

    1.png


    2. Integration into the project

    1) Solution

    You can encode and convert parameter values through the encodeURIComponent() method that comes with JavaScript.

    2) Example

    The same implementation is that the string "this%is#te=st&o k?+/" is passed to test.cpt as the value of the parameter t, and the corresponding code is as follows:

    window.location="http://localhost:8075/webroot/decision/view/report?viewlet=test.cpt&t="+encodeURIComponent(encodeURIComponent("this%is#te=st&o k?+/"));

    3) Explanation of two decodings

    The first encode is to remove the special characters and become an ASCII string (STR_ENC1), and the second encode is because the web container will automatically decode it once after it is obtained.

    The container req.getParameter is automatically solved this time, no matter whether it is GBK, UTF-8 or ISO-8859-1, it can be correctly obtained [STR_ENC1],

    If the JS is encoded only once, then the container can only be decoded in UTF-8 (the customer's Tomcat may have multiple encoding methods), otherwise the code is garbled, and finally the Java side will go to URLDecoder.decode

    Note: In the GET method, the container will automatically decode it once when req.getParameter is used, and then the report will be decoded again. In the POST method, the container will not automatically decode it, which means that when transmitting, you only need to encode it once.

    Attachment List


    Theme: Report Features
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy