jsp ajax get request Chinese gibberish problem solution

  • 2020-06-15 10:05:00
  • OfStack

The url code of Tocant is iso-8859-1(see Connector node of tocat/conf/ server.xml without URIEncoding="xxxxxx") as follows:


      <Connector port="8080" protocol="HTTP/1.1"
              connectionTimeout="20000"
              redirectPort="8443" />

If we write the following code in servlet

   
    String username = request.getParameter("name");//name  is get  The requested parameter , Here we have put get The requested bytecode is converted to iso-8859-1 The code of, decoding error 
    byte[] b = username.getBytes("iso-8859-1");// So you have to convert it back into bytecode, and decode it in the right way, and the right way is  jsp The way that page is encoded, 
    username =new String(b,"GBK");
    System.out.print(username );


Related articles: