Java Read database Chinese information, why in the JSP page garbled

Source: Internet
Author: User

There are several workarounds:

1, ensure that the character encoding of the project and each JSP page character encoding consistent, if inconsistent may lead to Chinese garbled problem <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
2, write the filter filter, in the filter method Dofilter
Request.setcharacterencoding ("UTF-8");

Response.setcontenttype ("Text/html;charset=utf-8");

Configure the following information in Web. XML to filter all requests
<filter>
<filter-name>characterFilter</filter-name>
<filter-class> Custom Filter Class full-qualified class name </filter-class>
</filter>
<filter-mapping>
<filter-name>characterFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3. Adding JSP configuration information to Web. xml
<jsp-config>
<jsp-property-group>
<description> for config the Web application </description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
In the JSP
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
The above three methods can be implemented, the second option is recommended, for any request, JSP and servlet can solve the Chinese problem

Java Read database Chinese information, why in the JSP page garbled

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.