In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the java parameter garbled how to do, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
For data submitted in Post mode, you can use request.setCharacterEncoding ("gb2312"); to explicitly specify the encoding to be used when getting request parameters. However, this method is only valid for Post submission.
Request.setCharacterEncoding ("gb2312"); the reason why the GET submission is invalid is that the code only sets the encoding of the request entity, and the data submitted by GET is the [resource name? param1= "Zhang San" & param2=123] stored in the request line, so the GET request method is invalid.
For the data submitted by Get, the garbled code can only be resolved manually:
String newName=newString (name.getBytes ("ISO8859-1"), "gb2312"); String user=newString (request.getParameter ("user") .getBytes ("ISO-8859-1"), "UTF-8")
Of course, this method is also effective for the Post approach.
The URIEncoding of the http connector can be configured in the server.xml of tomcat to specify the encoding that the server uses by default when getting the request parameters.
The following statements are usually used in servlet to solve the problem of Chinese garbled code:
Request.setCharacterEncoding () is to set the value taken from the request or fetched from the database.
The purpose of response.setContentType () is to control the behavior of the browser, that is, to control the browser to decode with the specified encoding (specifying the encoding of the HTTP response, as well as the encoding displayed by the browser).
The purpose of response.setCharacterEncoding () is for garbled strings output by response.getWriter (); this solution is not needed in the case of response.getOutputStream (), because this sentence is meant to decode the data in the response object in UTF-8 and send it to the browser.
Response.getOutputStream (). Write ("Chinese" .getBytes ()) outputs data, which is a byte stream that uses whatever encoding is used to write to memory.
Thank you for reading this article carefully. I hope the article "what to do with java parameters" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.