JSP Chinese display problems

Source: Internet
Author: User
Recently, I learned JSP and encountered Chinese display problems like most beginners. There are two Chinese problems:
(1) The Chinese characters that appear on the page itself. The solution is to add
<% @ Page Language = "Java" contenttype = "text/html; charset = gb2312" pageencoding = "gb2312" %>
Or <% @ page Language = "Java" contenttype = "text/html; charset = gb2312" %>
You can also change the above gb2312 to GBK, so that the Chinese characters displayed on the JSP page are correctly displayed.

(2) The value of the request parameter on the JSP page is in Chinese, both request. the value obtained by getparameter ("attributename") is Chinese. If no setting is added, the display will fail. There are two solutions:
1) before all request. getparameter ("attribute") appears, add
Request. setcharacterencoding ("gb2312 ");
Or request. setcharacterencoding ("GBK ");
2) The second method is to add the value after each string attributename = request. getparameter ("attributename") Statement
Attributename = new string (attributename. getbytes ("ISO-8859-1"), "gb2312 ");
Or attributename = new string (attributename. getbytes ("iso8859_1"), "gb2312 ");
Or attributename = new string (attributename. getbytes ("ISO-8859-1"), "GBK ");
PS: The method marked as 1) and 2) cannot be used at the same time. Otherwise, the method fails at the same time and can only be used.

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.