Solution to the problem of url automatic truncation when the parameter value passed by url is included
- 2021-07-07 06:07:07
- OfStack
1. The problem is raised
When doing a bulletin browsing function, as long as a parameter value passed through url contains & amp; Or & nbsp; A problem occurs--the value of the variable cannot be displayed.
Problem location result: encountered & The value of the parameter is automatically truncated, resulting in an incorrect parameter value passing.
2. Problem solving
Do the following tests in the java code:
String charEncode = java.net.URLEncoder.encode("
&
");
System. out. println ("Character
&
The translated value is: "+ charEncode); //Output:% 26
Therefore, the solution appears-before passing parameters, the & Replace all with% 26
eg:
var url = "page. jsp? para1=a & b "
Make the following modifications:
var url = "page.jsp?para1=a%26b";
At this point, the problem has been solved satisfactorily. n_n