Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the garbled code problems in the use of JSP virtual hosts

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the garbled code problems in the use of JSP virtual hosts. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

1 POST submission form is garbled

The common situation is: the page is normal, but the newly inserted data is garbled.

In this case, it is because the submitted data is garbled after it is received by the program, and the garbled code is inserted into the database, so the display is abnormal.

Solution:

A modify the configuration to complete

Modify the connector in tomcat's configuration file server.xml and add URIEncoding= "GB2312" to OK

B write the transcoding program by yourself

B.an is flexible when exchanging data with forms.

Each page requests to write a transformation, or write a public class, when receiving, make a transfer, the code is as follows:

Public static String ISOGBChange (String s)

{

Return EncodeChange (s, "ISO8859-1", "GB2312")

}

Public static String EncodeChange (String sperfine string source_encode,String dest_encode)

{

If (s==null)

Return null

Try

{

Byte [] tmpbyte = s.getBytes (source_encode)

S = new String (tmpbyte,dest_encode)

Return s

}

Catch (Exception e)

{

Return "ERROR"

}

}

B. b uses the filter filter defined in tomcat's web.xml to convert all request codes

This needs to study the writing of the filter, and then the specific conversion coding, or the code in B. a for coding conversion, but the transfer no longer has to be written in each program.

2 there are already garbled codes in the database

That is to say, the data in the database is garbled. No matter what code you use to connect to the database, what you see is garbled. How to make sure that the database is already garbled? (in fact, it is not easy to determine, we only give a general judgment.)

When you use the client to connect to the database, be sure to choose the connection coding to GB2312,UTF-8,ISO-8859-1 and other common coding format, connect and check whether the contents of your table is normal, if none of the cases is normal, you should be able to determine that it is garbled.

Of course, this decision is not standard, even a lot of problems, but in China, I think more than 99% of these codes are used. So I think the accuracy of this judgment is acceptable.

Solution: when you use the client to connect to the database, be sure to choose the connection code as GB2312 or GBK, and then re-execute the database script to ensure that the normal characters are stored in the database. Not garbled.

3 the code extracted from the database is garbled.

The database used to be normal, but after connecting with JAVA, once extracted, it was all messed up.

Solution: modify the URL of the JAVA connection database, and add or modify the code in URL to UTF-8,characterEncoding=UTF-8. If there is a problem with the configuration of hibernate, the jdbc connection url cannot have a & symbol, which will lead to an error or will not take effect later. I will use & instead.

Do not think that if you are using GB2312, you will specify GB2312 here (personally, if you specify GB2312, the driver will do one more transcoding, so it will become garbled again)

Of course, it is also possible to drive situations such as too old.

This is the end of this article on "what are the garbled codes in the use of JSP virtual hosts?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report