A summary of the solution for JSP Chinese garbled problem

Source: Internet
Author: User
Tags character set string
js| Solution | problem | chinese | Chinese garbled

In the process of using JSP, the most annoying problem is the Chinese garbled problem, the following is my software development encountered in the garbled problem and the solution.

1, JSP page garbled

The reason for this garbled is that the character set encoding should not be specified for use in the page, as long as you specify the character set code in the page at the beginning,

2, the database garbled

This garbled will make you insert the database into garbled Chinese, or read out the display is garbled, the solution is as follows:
To add a coded character set to the database connection string
String url= "jdbc:mysql://localhost/digitgulf?user=root&password=root&useunicode=true& characterencoding=gb2312 ";
and use the following code in the page:
Response.setcontenttype ("text/html;charset=gb2312");
Request.setcharacterencoding ("gb2312");

3, Chinese as a parameter transmission garbled

When we pass a paragraph of Chinese characters as a parameter to another page, there will be garbled situation, the solution is as follows:
The parameter is encoded when the parameter is passed, for example
Rearshres.jsp?keywords= "+ java.net.URLEncoder.encode (keywords)
Then use the following statement on the receive Parameters page to receive
Keywords=new String (request.getparameter ("keywords"). GetBytes ("8859_1"));

4, JSP page garbled add this sentence

<%@ page contenttype= "text/html; charset=gb2312 "language=" java import= "java.sql.*" errorpage= "err.jsp"%>



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.