Home  >  Article  >  Java  >  How to solve the problem of garbled parameters received in java

How to solve the problem of garbled parameters received in java

王林
王林Original
2020-05-21 16:20:003634browse

How to solve the problem of garbled parameters received in java

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=&#39;/product/download.action?documentPath=&#39;/>"+documentPath;
  url = encodeURI(encodeURI(url));
  window.location.href=url;
}
</script>

Get Chinese in the java code:

String documentPath = (String) request.getParameter(&#39;documentPath&#39;);
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(&#39;documentPath&#39;),"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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn