How to encode a URL with the special character “percentage”?

前端 未结 4 1651
你的背包
你的背包 2021-01-24 08:43

I am trying to use the encodeURL method in a jsp to encode a URL with \"%\" symbol.

response.encodeURL(/page1/page2/view.jsp?name=Population of 91% in

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-24 08:47

    The result of your code is :

    %2Fpage1%2Fpage2%2Fview.jsp%3Fname%3DPopulation%20of%2091%25%20in%20this%20place
    

    You should encode only the query string value.

    ... = "/page1/page2/view.jsp?name=" + URLEncoder.encode('Population of 91% in this place');
    

    ?

提交回复
热议问题