Home > Java > Java Tutorial > body text

What to do if java objects are garbled

coldplay.xixi
Release: 2020-08-17 11:41:10
Original
1902 people have browsed it

Solutions to garbled java objects: 1. When downloading garbled files, the download response header and filename must be encoded with URLEncoding before HTTP transmission; 2. For garbled files between java and the database, directly use unicode and To interact with the database, you can specify it in the driver's URL.

What to do if java objects are garbled

Solution to Java object garbled code:

Garbled code between jsp and page parameters

Forcefully specify the request encoding method:

request.setCharacterEncoding("UTF-8");
Copy after login

If the jsp output to the page appears garbled:

response.setCharacterEncoding("UTF-8");
Copy after login

Or configure the servlet filter filter in web.xml (only Valid for POST mode, invalid for GET mode):


CharacterEncodingFilter
net.vschool.web.CharacterEncodingFilter

encoding
UTF-8



CharacterEncodingFilter
/*
Copy after login

Change Tomact configuration file, server.xml

Copy after login

URL processing:

" >
Copy after login

File download garbled code:

The key is the response header when downloading; filename must be encoded with URLEncoding for HTTP transmission.

response.setHeader("Content-disposition", "attachment;filename="+ URLEncoder.encode(fileName,"utf-8"));
Copy after login

Get method garbled code:

String args = new String(strCn.getBytes("ISO-8859-1"),"UTF-8");
Copy after login

Post method garbled code:

Just request.setCharacterEncoding(" UTF-8"); is enough.

Garbled characters between java and database

Use unicode directly to interact with the database, which can be specified in the driver's url, such as mysql driver:

 jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=utf-8
Copy after login

Related learning recommendations: java basic tutorial

The above is the detailed content of What to do if java objects are garbled. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!