Solution of Garbled Chinese Code in js Value Transmission Background

  • 2021-07-01 06:18:14
  • OfStack

This paper describes the solution to the garbled code in the background of js value transmission. Share it for your reference, as follows:

In the "test. jsp" page, you need to pass the value to the background through js. When the background performs data query according to the passed value, you can encode it through js of test. jsp (the code of the annotation part) and decode it through Java in the background (the annotation annotation part is decoding), which can solve the problem

test. jsp:


<script type="text/JavaScript" charset="UTF-8">
function test()
{
// Below 2 The line code is a pair js The value passed is encoded: 
   var faultAddr = encodeURI(document.getElementById("faultAddr").value);
  faultAddr = encodeURI(faultAddr); // It needs to be coded twice 
  window.frames["listframe"].location.href ="queryorderList.action?faultAddr=" + faultAddr ;
}
</script>
 ... 
<tr>
<td height="5%" width="50"> Complaint address </td>
  <td>
    <input id="faultAddr" maxlength="300" size="10" name="faultAddr" type="text" value=""/>
  </td>
</tr>

java code:


String faultAddr =request.getParameter("faultAddr");
try{
  faultAddr = URLDecoder.decode(faultAddr , "utf-8");// Coding and decoding 
}catch(Exception e){
  e.printStackTrace();
}

For more readers interested in JavaScript, please check the topic of this site: "Summary of javascript coding operation skills", "Summary of JavaScript value transmission operation skills", "Summary of json operation skills in JavaScript", "Summary of JavaScript switching special effects and skills", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation special effects and skills", "Summary of JavaScript error and debugging skills", "Summary of JavaScript data structure and algorithm skills", "Summary of JavaScript traversal algorithm and skills" and "Summary of JavaScript mathematical operation usage"

I hope this article is helpful to everyone's JavaScript programming.


Related articles: