Chinese garbled characters often occur during JSP development, which may affect you, I am writing out the Chinese garbled characters I encountered during JSP development and the solutions for your reference.
I. Garbled characters on the JSP page
The following display Page (display. jsp) is garbled:
<Html>
<Head>
<Title> JSP Chinese processing </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<%
Out. print ("JSP Chinese processing ");
%>
</Body>
</Html>
Different WEB servers and JDK versions have different processing results. Cause: The encoding method used by the server is different from that used by the browser to display different characters. Solution: specify the encoding method (gb2312) on the JSP page, that is, add <% @ page contentType = "text/html; charset = gb2312 "%> to eliminate garbled characters. The complete page is as follows:
<% @ Page contentType = "text/html; charset = gb2312" %>
<Html>
<Head>
<Title> JSP Chinese processing </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<%
Out. print ("JSP Chinese processing ");
%>
</Body>
</Html>
2. Garbled characters appear when the form is submitted to Chinese
The following is a submission page (submit. jsp). The code is as follows:
<Html>
<Head>
<Title> JSP Chinese processing </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<Form name = "form1" method = "post" action = "process. jsp">
<Div align = "center">
<Input type = "text" name = "name">
<Input type = "submit" name = "Submit" value = "Submit">
</Div>
</Form>
</Body>
</Html>
The following is the process. jsp code:
<% @ Page contentType = "text/html; charset = gb2312" %>
<Html>
<Head>
<Title> JSP Chinese processing </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
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