In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the solutions to common character coding problems in Java web applications. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
The following are common coding problems for Java web applications
1. Coding of html pages
In web applications, browsers usually decide what encoding to use based on the value of http header: Content-type. For example, when you encounter Content-Type: text/html; charset=UTF-8, the page uses UTF-8 encoding. However, considering the offline html (users may save the page html locally), when opening the offline html, you have to specify the encoding in the meta, of course, there will be a default value if not specified, then garbled code may sometimes occur if it is not specified.
Meta tag
2. Coding of Http Request
Usually, when browsing sends a request to the server, the character encoding is not set. In order to unify the encoding on the server side, you can use request.setCharacterEncoding ("UTF-8") in filter to set the encoding. General browsers use the default ISO-8859-1 character encoding, which is a necessary step to solve garbled Chinese parameters.
3. Coding of http response
The encoding methods that can be used in http response to set the data output to the browser are response.setCharacterEncoding ("UTF-8") and response.setContentType ("text/html; charset=UTF-8"). If you simply set the encoding, * * use response.setCharacterEncoding ("UTF-8"), because response.setContentType ("text/html; charset=UTF-8") sets the corresponding character encoding for a specific MIME type. It is important to note that the encoding set here does not necessarily work for JSP pages because JSP pages have their own way of setting character encoding and have a higher priority.
4. Coding of JSP pages
There are three ways, if there are both * and the second, only one will take effect (if different)
There are other species and the second will cover the third.
* Note that when declaring the encoding type using 1) or 2), if there are other JSP in the page, and for the difference between and, assuming that the former method includeBB.jsp is used in AA.jsp, then there can be no declaration of duplicate encoding in BB.jsp. The effect is that both AA.jsp and BB.jsp are encoded using the encoding method declared in AA.jsp.
If you are using the latter include approach, both AA.jsp and BB.jsp can have their own coded declarations.
1)
2)
3) add the following settings to web.xml
* .jsp UTF-8
5. Setting of mime in web.xml and weblogic.xml
You can specify the mime mapping in web.xml, as well as the character encoding used by the corresponding type (the settings here can also be done using the http response.setContentType and response.setCharacterEncoding mentioned in 3), such as:
Html text/html; charset=UTF-8
You can set the default mime type and character encoding in weblogic.xml
Text/html; charset=UTF-8
And
/ * UTF-8
Generally speaking, the same character encoding is explicitly specified in html, http request, http response and jsp pages in an application, and the most convenient thing is to set it to UTF-8, so that all characters will not make an error. The setting for mime mapping * is set in web.xml. The settings for character encoding in weblogic generally do not need to be set (if you set all the above correctly).
The solutions to the common character coding problems in Java web applications are shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.
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.