search

Home  >  Q&A  >  body text

java - servlet传汉字到jsp乱码

response.sendRedirect("content/template/zpsc.jsp?path="+realPath+"&responseText="+responseText+"");
realPath里有汉字
'''response.setContentType("text/html; charset=utf-8");
request.setCharacterEncoding("utf-8"); ''不管用

巴扎黑巴扎黑2834 days ago670

reply all(7)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 11:49:45

    Is your front-end receiving data javascript or jsp? If it is javascript, in the background you can use escape() to encrypt the text, and then use unescape() in javascript to decrypt it. Because JavaScript comes with these two methods for encryption and decryption, which is more convenient. These two encryption and decryption methods have been implemented by experts on the Internet using Java. You can add a tool class and then encrypt in the background in this way, and use JavaScript's own methods to decrypt in the foreground. There must be no garbled characters. If you are using jsp to receive data, it is recommended not to use this method. You can use some built-in objects to pass values.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:49:45

    Response.sendRedirect("content/template/zpsc.jsp?path="+URLEncoder.encode(realPath, "UTF-8")+"&responseText="+URLEncoder.encode(responseText,"UTF-8") +"");

    Be a good person

    reply
    0
  • PHPz

    PHPz2017-04-17 11:49:45

    This is definitely not possible. If you are passing the value through the URL, there will be a transcoding problem

    The simpler and more orthodox way is to pass values ​​through built-in objects such as request, session, and application

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 11:49:45

    If you want to transfer Chinese characters through URL, you must first convert the Chinese characters into unicode

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 11:49:45

    Transfer values ​​through built-in objects such as request, session, and application

    reply
    0
  • 阿神

    阿神2017-04-17 11:49:45

    Front-end js: encodeURI(encodeURI(tag))

    Backend java code: String tag = URLDecoder.decode(tag, "utf-8");

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:49:45

    How about writing a character filter and giving it a try?

    reply
    0
  • Cancelreply