search
HomeJavaJavaBaseSolution to garbled request in java

Solution to garbled request in java

Dec 30, 2019 am 09:43 AM
javarequestGarbled characters

Solution to garbled request in java

Solution to Chinese garbled POST:

POST passes parameters through the request body. Set the encoding method of the response character stream to UTF-8.

request.setCharacterEncoding("UTF-8"); This sentence solves the problem of Chinese garbled characters submitted in POST mode. This method sets the character encoding in the request body, so the server will parse it according to UTF- 8 is decoded. But this method has no effect on the get method.

(Recommended: java video tutorial)

GET Chinese garbled code solution

GET method passes parameters through the url.

// 下面的方式可以解决post或者get方式的中文乱码问题
// 这里接收的name是iso8859-1的字符编码
String name = request.getParameter("username");
// 将name字符串按照原来字符编码打散
byte[] bytes = name.getBytes("ISO8859-1");
// 将bytes字节数据按照指定字符编码字符编码进行组装,组装为String
name = new String(bytes, "UTF-8");
//真正的写法:name = new String(name.getBytes("ISO8859-1"), "UTF-8");

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Solution to garbled request in java. For more information, please follow other related articles on the PHP Chinese website!

Statement
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 admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)