Several methods to solve the problem of JSP Chinese display

Source: Internet
Author: User
The following methods are summarized to solve the problem of JSP Chinese display: 1. Add a Statement on the jsp page: <% @ page contentType = "text/html; charset = gb2312 "%> the Chinese display is normal. 2. For the text box from the webpage, use String parameter = request. the String obtained by getParameter ("parameter"); is 8859_1 encoded. to display it on a webpage, you must use parameter = new String (parameter. getBytes ("8859_1"), "gb2312") for conversion. Both windows and linux systems are the same. A simple method is to use request. setCharacterEncoding ("GB2312"); to convert the submitted information to GB2312 encoding before the getParameter () method obtains the parameter. 3. However, the method for writing data to the database is different: in windows, the string must be converted and inserted into the database, which is not required in linux, instead, the 8859_1 encoding characters are inserted directly. If the data read from the database has been converted during insertion in windows, it is gb2312. When it is displayed on a webpage, you do not need to perform encoding conversion, while mysql Data in linux is 8859_1. 4. If you assign a value to a Chinese character string to a string variable, you do not need to convert the display on the webpage when you retrieve the value, however, if you want to compare characters in linux, you also need to set the character as parameter = new String (parameter. getBytes ("gb2312"), "8859_1") conversion. 5,The Changjiang Electric Power website solves Chinese problems:1) In catalina. sh file. encoding = GBK/2) Add the following two lines at the beginning of each jsp file <% @ page contentType = "text/html; charset = GBK" %> <% request. setCharacterEncoding ("GBK"); %>
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.