5 ways to solve the JSP page garbled

Source: Internet
Author: User
Tags character set config

JSP programming in the Web page appears garbled, the basic can be grouped into 5 categories:

1. JSP page display garbled.

2. When the servlet receives the parameters passed by Form/request, it is displayed as garbled

3. JSP to receive form/request passed parameters when displayed as garbled

4. <jsp:forward page= "catalog2.html" when the page display garbled

5. Database access to generate garbled.

Here's how to solve all of the following:

Steps/Methods

1. JSP page display garbled.

The first is to add at the beginning of the page:

<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding=" GBK "%>

Note: Sometimes if you don't add this sentence at the beginning of the page, you cannot save the Chinese character in the page and prompt: Chinese characters cannot be mapped by the iso-8859-1 character set, which is because by default the JSP is encoded with iso-8859-1 and can be window-> Under the preferences->general->content type option, select text->jsp on the right window, and then change from default Iso-8859-1 to GBK in the following defaults encoding Then click Update to resolve.

This column more highlights: http://www.bianceng.cn/webkf/JSP/

This approach, however, poses some problems: because this sentence cannot be inherited when other files include the file, the file including it also needs to be added to the beginning of the file, and there is a problem with pageencoding= "GBK". Similar to org.apache.jasper.JasperException:/top.jsp (1,1) Page Directive:illegal to have multiple occurrences of ContentType W ith different values (OLD:TEXT/HTML;CHARSET=GBK, NEW:TEXT/HTML;CHARSET=GBK).

Similarly, if two files are GBK and one is gb2312, a problem will arise.

Another way to better solve the problem is to:

Add the following fragment to the project's Web.xml:

<jsp-config>

<jsp-property-group>

<description>

Special Property Group for JSP Configuration JSP example.

</description>

<display-name>JSPConfiguration</display-name>

<url-pattern>*.jsp</url-pattern>

<el-ignored>true</el-ignored>

<page-encoding>GBK</page-encoding>

<scripting-invalid>false</scripting-invalid>

<include-prelude></include-prelude>

<include-coda></include-coda>

</jsp-property-group>

<jsp-property-group>

<description>

Special Property Group for JSP Configuration JSP example.

</description>

<display-name>JSPConfiguration</display-name>

<url-pattern>*.html</url-pattern>

<el-ignored>true</el-ignored>

<page-encoding>GBK</page-encoding>

<scripting-invalid>false</scripting-invalid>

<include-prelude></include-prelude>

<include-coda></include-coda>

</jsp-property-group>

</jsp-config>

2

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.