Three Common examples of JSP Chinese garbled characters and their solutions: jsp garbled characters

Source: Internet
Author: User

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.

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.