如何使用特殊字符“百分比”编码URL [英] How to encode a URL with the special character "percentage"?
问题描述
我试图在jsp中使用 encodeURL
方法来编码一个带有%符号的URL。
response.encodeURL(/page1/page2/view.jsp?name=在这个地方拥有91%的人口)
无论何时点击按钮,网站无法显示
错误。
但是,当您手动将%
符号更改为%25
像这样这个地方的91%25人口
,然后显示正确的页面。
此外,每当%
符号最后被放置在这个在这个地方人口91%
,那么页面正确显示,但我注意到,在地址栏中,它仍然显示为%
而不是%25
并且仍然工作。
当我搜索时,它提到只使用其他方法,如 encodeURI() &安培;你可以给我一个解决方案,但仍然使用
encodeURL
c $ c $即使有%
符号也能正确显示页面的方法。我应该使用 replace()
或为什么isnt encodeURL()
方法正常工作?
代码的结果是:
% 2Fpage1%2Fpage2%2Fview.jsp%3Fname%3DPopulation%20of%2091%25%20in%20th%20place
您应该仅编码查询字符串值。
... =/page1/page2/view.jsp?name =+ URLEncoder.encode(这个地方的人口为91%);
?
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 this place)
Whenever the button is clicked, "The website cannot display the page"
error is shown.
But when you manually change the "%"
symbol to "%25"
like this "Population of 91%25 in this place
",then the correct page is displayed.
Also whenever the "%"
symbol is placed at last like this "In this place Population of 91%
", then the page is correctly displayed but i noticed that in the address bar its still shown as "%"
and not as "%25"
and still its working.
When I searched around, its mentioned only to use the other methods like encodeURI() & encodeURIComponent().
Can you suggest me a solution while still using the encodeURL
method to display the pages correctly even if there is a "%"
symbol. Should i use replace()
or why isnt the encodeURL()
method working correctly?
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');
?
这篇关于如何使用特殊字符“百分比”编码URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!