This article describes the implementation method of solving the garbled code problem through json passing values in struts2. Share it for your reference, as follows:
In struts2, if you use json to pass Chinese values in jsp and java files, you can often get garbled Chinese access. If you use json to pass Chinese values in jsp and java files, you can use the following method to solve this problem.
1. Use encodeURI to encode in js file, example:
var url = "orderPrint.action?roomName="+encodeURI(encodeUR(roomName));$.post(url,function(data){ } 2. Use encodeURI to decode in java files , example:
The code copy is as follows: String room =URLDecoder.decode(orderBean.getRoomName(),"utf-8");
In this way, what the room parses out is the correct Chinese, and it will not be garbled.
I hope that this article will be helpful to everyone's Java programming based on the Struts framework.