Solutions to JSP Chinese problems

Source: Internet
Author: User

Chinese garbled characters in JSP are often messy.
The following two common countermeasures are often visible on the Internet:

<% @ Page
Contenttype = "text/html; charset = gb2312" %>

Or:

<%
String HI = "hello ";
Byte []
Tmpbyte = Hi. getbytes ("iso8859_1 ");
Hi = new
String (tmpbyte );
Out. Print (HI );
%>

The virtual Dragon pavilion also uses the above two methods for modification, thus becoming version 1.1.

Through a simple summary, the Chinese processing in the example takes place in the following places:

1. the URL contains Chinese parameters and can be directly read.

For example:

<% = Request. getparameter ("showword") %>

2. Database-related SQL operations

There is no problem with access.

3. Read html

Chinese value submitted in Form

In jswdk, the code is required. The concise method is as follows:

String name1 = new
String (request. getparameter ("user_id"). getbytes ("iso8859_1 "));

In addition, jdk1.3 does not need to be added.

<% @
Page contenttype = "text/html; charset = gb2312"
%>

In jdk1.2.2, even the two methods are not stable at the same time.

On the resin platform, the situation is good. Add the following content to the first line of the page:

<% @
Page contenttype = "text/html; charset = gb2312"
%>

You can process Chinese characters correctly.

If the encoding is added, it is not correct.

5. Chinese characters contained in the session

In jswdk, it is strange that if the value read from form is encoded, it can be correctly displayed;
However, it is not possible to assign a Chinese value directly.
The resin platform is good, just like above.

6. If a Chinese value is assigned to the variable, the Chinese name is displayed correctly.

For example:Program:

<% @ Page contenttype = "text/html; charset = gb2312"
%>
<HTML> <%
String
Hi = "hello ";
Byte [] tmpbyte = Hi. getbytes ("iso8859_1 ");
Hi = new
String (tmpbyte );
Out. Print (HI );
%>
</Body>

Jswdk1.0.1 is the same. The above representation is correct in jdk1.2.2, but cannot be displayed in jdk1.3.

The resin platform is good. Same as above. After testing, you only need to add it in

<Meta
HTTP-equiv = "Content-Type" content = "text/html;
Charset = gb2312 ">
No <% @ page
Contenttype = "text/html; charset = gb2312" %> Chinese characters can also be correctly displayed.

Experience:

Jswdk may only be used for common development, and stability and other problems may be inferior to commercial software.
Jdk1.3 has better performance than jdk1.2.2 many times and better support for Chinese, so it should be adopted.

As a free commercial software, resin is not only fast, stable, and automatically compiled, but can indicate error lines and support JavaScript on the server side. Moreover, at least I think the support for Chinese is good.

Of course, if you do not have to do anything to display Chinese correctly, it will be what we expect.

In addition, we believe there should be no such problem in Unix/Linux/Solaris.

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.