Study on processing Chinese garbled characters in JSP Dynamic Web-page program
Source: Internet
Author: User
js| Program | news | web | chinese | Garbled in JSP, Chinese garbled often makes people utterly confused.
For
The common countermeasures of Chinese processing, often visible on the Internet are mainly the following 2 kinds:
<%@ page
Contenttype= "text/html;charset=gb2312"%>
Or:
<%
String hi= "Hello";
Byte[]
Tmpbyte=hi.getbytes ("Iso8859_1");
Hi=new
String (Tmpbyte);
Out.print (Hi);
%>
Virtual small Longting also mainly used the above 2 methods have been modified, thus becoming the 1.1 version.
By simply summarizing, the Chinese processing in the example occurs in several places:
1 in the URL with Chinese parameters, you can read directly.
For example:
<%= request.getparameter ("Showword")%>
2
Various SQL operations related to the database
There is no problem with access in this place.
3 Reading HTML
Form Table consignments the Chinese value submitted
In the JSWDK need to be coded, more concise wording such as:
String name1=new
String (Request.getparameter ("user_id"). GetBytes ("Iso8859_1"));
In addition, with the support of jdk1.3, there is no need to join
<%@
Page contenttype= "text/html;charset=gb2312"
%>
Under jdk1.2.2, even 2 methods are not stable at the same time.
But in the resin platform, the situation is better. Just add in the first line of the page:
<%@
Page contenttype= "text/html;charset=gb2312"
%> can handle Chinese correctly.
If you add code then it is wrong.
5
Chinese included in the session
In JSWDK, it is strange that if the value read from form is encoded, it can be displayed correctly;
But it is not possible to give Chinese values directly.
Resin platform is very good, ditto.
6 correctly displays Chinese after assigning Chinese values to variables.
For example, the following programs:
<%@ page contenttype= "text/html;charset=gb2312"
%>
<%
String
hi= "Hello";
Byte[] Tmpbyte=hi.getbytes ("iso8859_1");
Hi=new
String (Tmpbyte);
Out.print (Hi);
%>
</body>The same is jswdk1.0.1, the above method of representation in the jdk1.2.2 no problem, but under the jdk1.3 can not be displayed.
Resin platform is very good, ditto, after testing, only need to fill in the <meta
http-equiv= "Content-type" content= "text/html;
charset=gb2312 ">
Without the need to <%@ page
Contenttype= "text/html;charset=gb2312"%> can also display Chinese correctly.
Experience:
JSWDK may only be used for general development, and stability and other problems may not be as good as commercial software.
Because the jdk1.3 version performance is better than jdk1.2.2 many times, and the Chinese support is also good, so should be adopted.
As a free commercial software, resin not only fast, stable, automatic compilation, can point to error line, can support the use of JavaScript on the server side, and, at least, I think the support for Chinese is very good.
Of course, if you do not have to do any processing to correctly display the Chinese will be what we expect.
In addition, I believe that under the unix/linux/solaris should not have such a problem.
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.