You can try the following five methods to solve the problem:
1. Submit in form instead of hyperlink
2. Through encodeURI (encodeURI(checkText)) method submits
Use URLDecoder.decode to decode in the java code:
<script> function download(documentPath){ var url = "<c:url value='/product/download.action?documentPath='/>"+documentPath; url = encodeURI(encodeURI(url)); window.location.href=url; } </script>
Get Chinese in the java code:
String documentPath = (String) request.getParameter('documentPath'); documentPath = URLDecoder.decode(documentPath,"utf-8");
( Recommended video tutorial: java video)
3. Modify the connector in tomcat’s server.xml and add URLEncoding="UTF-8"
4. Chinese from java Transfer to jsp, and then transfer to java through url
Encoding in java:
URLEncoder.encode(URLEncoder.encode("传递的中文","utf-8"));
Decoding code in java:
URLDecoder.decode(request.getParameter('documentPath'),"utf-8");
5. Transcode the string in Java
String s = new String(filename.getBytes("ISO-8859-1"),"UTF-8");
Recommended tutorial: Getting started with java development
The above is the detailed content of How to solve the problem of garbled parameters received in java. For more information, please follow other related articles on the PHP Chinese website!