Why can I transmit Chinese characters in the form mode, but the URL mode cannot? Can the problem be solved only when URL-based value passing is required? Here I think of a dynamic form. Why not use it to solve it? when developing a web application, data interaction between the front and back ends is required in many cases, sometimes we may need to pass the front-end Chinese data through the URL Method to the background, but at this time there is a headache, because the Java network transmission using the standard character set is ISO-8859-1, therefore, request is used in the background. getParameter ("message"); get the front-end passed Chinese, the obtained is the ISO-8859-1 Character Set, Chinese will appear garbled phenomenon, the solution for many people is to perform decode before the front-end transmits Chinese characters, and then decode the back-end for conversion. This is very troublesome. Isn't there any other solution?
I thought for a moment: why can I transmit Chinese characters in the form mode, but the URL mode cannot be used? Can the problem be solved only when URL-based value passing is required? Here I think of a dynamic form. Why not use it? The example is as follows:
For example, in the following scenarios: On the KPI list page, the alarm data is generated for each KPI. When you click the button for generating data for each KPI in the list, you need to pass the KPI id and name to the background.
Js method corresponding to the frontend:
Use the URL to pass the value:
The Code is as follows:
Function createData (indexId, indexName ){
Window. location. href = "catalogAction. do? Action = CreateIndexData & catalogId = "+ indexId +" & catalogName = "+ indexName +" & random = "+ Math. random ();
}
In this way, the KPI name is mostly Chinese, and the value received in the background must be garbled.
If you use the dynamic form generation method, you can solve the problem:
The Code is as follows:
Function createData (indexId, indexName ){
Var urlStr = "catalogAction. do? Action = CreateIndexData & PcatalogId = & CatalogId = "+ indexId +" & random = "+ Math. random ();
Var f = document. createElement ('form ');
F. action = urlStr;
F. method = 'post ';
Document. body. appendChild (f );
Var temp = document. createElement ('input ');
Temp. type = 'ddn ';
Temp. value = indexName;
Temp. name = 'catalogname ';
F. appendChild (temp );
F. submit ();
}
The Chinese field is submitted in form mode. If it is not Chinese, the URL is still used for transmission. This easily solves the problem of garbled Chinese characters passed to the background.