Solution to saving the jsp page to the database with garbled characters

Source: Internet
Author: User

Solution to saving the jsp page to the database with garbled characters
First: add
<% @ Page language = "java" contentType = "text/html; charset = gbk"
ErrorPage = "" %>
<% Request. setCharacterEncoding ("GBK"); %>

The first line indicates that your page uses Chinese encoding.
The second line declares that your page value is also encoded in Chinese.


Second
Tomcat4.x supports Chinese Character transfer, but 5.x does not. If you use a version later than 5.0, you have to transcode it,
This is the format
String strKeyWords = new String (request. getParameter ("key_words "). getBytes ("iso8859_1"), "gb2312"); this is a solution for our project to solve Chinese garbled characters.



Solution to saving the jsp page to the database with garbled characters

Jsp + tomcat + bean Chinese garbled problem solution an contains garbled Parameters
1) All jsp pages specify the character encoding method, such as: Charest = gb2312, Charest = UTF-8, etc.
2) Find the line for setting the server port in the server. xml component of the application server, which generally starts with this :" 3) Find the row" --------------------------------------------------------------------------
Jsp page garbled code Solution

All jsp pages specify character encoding methods, such as: Charest = gb2312, Charest = UTF-8, etc.
<% @ Page contentType = "text/html; charset = UTF-8">
--------------------------------------------------------------------------
Solution to garbled characters of a single Chinese parameter in jsp

Use this to convert:
<%! String trans (String chi)
{
String result = null;
Byte temp [];
Temp = chi. getBytes ("iso= 8859-1 ");
Result = new String (temp );
}
%>
Or directly:
<%
Request. setCharacterEncoding ("UTF-8 ");
Out. println (request. getParameter ("parameter ID ")
%>
--------------------------------------------------------------------------

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.