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.