Solution of Chinese garbled problem in JAVA post and get data transfer _jsp programming

Source: Internet
Author: User
Did n years of Java development has never written a website, recently scrambled to get an entrepreneur propaganda website.
As everyone encountered the Chinese character set garbled problem, in order to be able to take some detours less, so here to share a simple and practical solution.
1. POST Data transfer
Receive page
Copy Code code as follows:

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%
Request.setcharacterencoding ("UTF-8");
String zh_value=reqeust.getparameter ("Zh_value");
%>

The important places are the following two
Copy Code code as follows:

pageencoding= "UTF-8"//declaring the character set of the current page

Copy Code code as follows:

Request.setcharacterencoding ("UTF-8"); Declaring a request's character set

2. Get Data delivery
Receive page
Copy Code code as follows:

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%
String Zh_value=new string (Request.getparameter ("Zh_value"). GetBytes ("Iso-8859-1"), "UTF-8")
%>

The important places are the following two
Copy Code code as follows:

pageencoding= "UTF-8"//declaring the character set of the current page

Copy Code code as follows:

New String (Request.getparameter ("Zh_value"). GetBytes ("Iso-8859-1"), "UTF-8")// Decodes the acquired string into a byte array based on the iso-8859-1 and then generates a byte array based on the UTF-8 string

If you use the above method can not solve the problem, please be sure to give me a message, I can add more methods to go in for your reference.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.