java - servlet传汉字到jsp乱码
巴扎黑
巴扎黑 2017-04-17 11:47:45
0
7
656

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

巴扎黑
巴扎黑

reply all(7)
Peter_Zhu

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.

左手右手慢动作

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

Be a good person

PHPzhong

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

左手右手慢动作

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

伊谢尔伦

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

阿神

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

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

洪涛

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template