JSP Chinese garbled Problem Solution

Source: Internet
Author: User

Yesterday, I spent more than two hours submitting JSP form data and saving it to the database with Chinese garbled characters. Today I finally solved the problem. Here are some operations to help you.

The main problem is coding. There are a lot of problems on Baidu. Some problems can be solved, and some cannot be solved using the same method. I have limited knowledge. I don't know why. Here I will only talk about my methods.

The main solution is to watch Han shunping's video. The method is as follows:

First, add an encoding class. The Code is as follows:

Public class tools {

Public static string change (string input ){
String output = "";
Try {
Output = new string (input. getbytes ("iso-8859-1"), "UTF-8 ");
} Catch (exception e ){
E. printstacktrace ();
}
Return output;
}
}

Change <% @ page contenttype = "text/html" pageencoding = "gb2312" %> to <% @ page contenttype = "text/html" pageencoding = "UTF-8" %>

For example, if I want to obtain data in a form named concernname, add this statement to concernname = tools. Change (concernname), and save the concernname to the database.

Concernname = request. getparameter ("concernname ");
Concernname = tools. Change (concernname );

Related Article

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.