Three Common examples of JSP Chinese garbled characters and their solutions: jsp garbled characters
Three Common examples and solutions are as follows:
Instance 1: When the JSP page is displayed
<Html>
Running result:
Solution:Specify a Chinese character set for it, before
<% @ Page contentType = "text/html; charset = gb2312" %>
Example 2: When the JSP page passes Chinese Parameters
Registration page:
<% @ Page contentType = "text/html; charset = gb2312 "%>
Personal information page:
<% @ Page contentType = "text/html; charset = gb2312 "%>
Running result:
Solution:The modify personal information page is as follows:
<% @ Page contentType = "text/html; charset = gb2312 "%>
Example 3: When the Servlet processes Chinese Parameters
Registration page:
<% @ Page contentType = "text/html; charset = gb2312" %> <% @ page import = "test. userMsg "%>
UserMsg. java (Servlet)
Package test; importjava. io. IOException; importjava. io. printWriter; importjava. io. unsupportedEncodingException; importjavax. servlet. http. httpServlet; importjavax. servlet. http. httpServletRequest; importjavax. servlet. http. httpServletResponse; public classUserMsg extends HttpServlet {public void doGet (response, HttpServletResponse response) {doPost (request, response);} public void doPost (response, HttpServletResponse response) {try {request. setCharacterEncoding ("gb2312");} catch (unsupportedencodingeffectione) {e. printStackTrace ();} PrintWriter out = null; try {out = response. getWriter ();} catch (IOException e1) {e1.printStackTrace ();} out. print ("
Running result:
Solution:Add the following to doPost:
Response. setContentType ("text/html; charset = gb2312 ");
The above are several common examples of Chinese garbled JSP code and their solutions, hoping to help you solve the problem of Chinese garbled JSP code.