In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to solve the problem of Chinese garbled code in jsp". In daily operation, I believe that many people have doubts about how to solve the problem of Chinese garbled code in jsp. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubt of "how to solve the problem of Chinese garbled code in jsp". Next, please follow the editor to study!
Simply solve the problem of garbled codes in jsp
Make a simple response page for beginners to learn jsp
The specific code is as follows:
Username: Hello
Save as a test.jsp file, start tomcat access, and the following figure appears:
Enter: vae in the box. The following figure appears:
But "username" looked really uncomfortable and decided to change it to "user name"
User name: Hello
Then the problem arises:
There is a string of garbled codes where the "user name" should have appeared:
The so-called garbled code in the response is to display the garbled code on the page, because the page data is put into the response (response) from one end of the server and then sent to the browser. If the data in the response cannot be parsed properly, the garbled problem will occur.
Why is there no problem with English? Because in iso-8859-1 gb2312, utf-8 and any other encoding format, the English encoding format is the same, each character occupies 8 bits, while Chinese is troublesome. In gb2312, the next Chinese occupies 16 bits, two bytes, while in utf-8, the next Chinese occupies 24 bits, three bytes.
Without knowing how to determine the encoding, the browser will truncate these characters in the middle and mess up when they are displayed.
So, to solve the garbled problem is to tell the browser exactly what kind of coding we use.
Under windows, the default encoding format of files is gb2312.
The solution is as follows:
(1) add coding information to the http response (response)
This paragraph is placed on the first line of the jsp page to specify the type and encoding format of the response. ContentType is text/html is html content, and charset means encoded as gb2312. This allows the browser to get the encoding format from the response.
(2) specify the encoding format in html
Title
The meta section is used to specify the encoding format of the current html. Note that this paragraph should be placed in the head tag and in front of the head tag. If it is not the front ie, there may be problems, especially if there is Chinese in the title.
The above two tests are to ensure that the output of jsp web pages is in Chinese.
The modified code is as follows:
Title user name:
Run again:
At this point, the study on "how to solve the jsp Chinese garbled problem" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.