JSP Chinese garbled characters: Garbled characters are displayed when the JSP page is called.
When a JSP page is called through a browser, all Chinese content in the client browser is garbled.
Solution:
First, confirm that the encoding format of GBK is used when the JSP file is saved in the editor, add <% @ pageEncoding = "GBK" %> at the beginning of the JSP page to solve Chinese garbled characters.
JSP Chinese garbled problem 2: Garbled characters are displayed when the Servlet page is called.
When Servlet is called through a browser, the Servlet displays garbled content in the browser.
Solution:
Before using response in Servlet to output content, execute response. setContentType ("text/html; charset = GBK") to set the encoding of the output content to GBK.
JSP Chinese garbled problem 3: Garbled parameters passed in the Post form
Submit parameters to the corresponding JSP page or Servelt through the JSP page, HTML page, or form Element in the Servlet. The Chinese parameter values received by the JSP page or Servlet are garbled.
Solution:
Before receiving parameters submitted by POST, use request. setCharacterEncoding ("GBK") to set the content of the received parameters to be encoded by GBK.
A better solution to JSP Chinese garbled characters is to use the filter technology.
Encoding filter
- package com.htt;
-
- import java.io.IOException;
-
- import javax.servlet.Filter;
-
- import javax.servlet.FilterChain;
-
- import javax.servlet.FilterConfig;
-
- import javax.servlet.ServletException;
-
- import javax.servlet.ServletRequest;
-
- import javax.servlet.ServletResponse;
-
- public class Encoding implements Filter {
-
- public void destroy() { }
-
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
-
- request.setCharacterEncoding("GBK");
-
- chain.doFilter(request, response);
-
- }
-
- public void init(FilterConfig filterConfig) throws ServletException { }
-
- }
Settings in the Web. xml file
- < filter>
-
- < filter-name>encoding< /filter-name>
-
- < filter-class>com.htt.Encoding< /filter-class>
-
- < /filter>
-
- < filter-mapping>
-
- < filter-name>encoding< /filter-name>
-
- < url-pattern>/ToCh_zn< /url-pattern>
-
- < /filter-mapping>
JSP Chinese garbled Problem 4: Get form transmission and URI Transmission Parameters garbled
Solution
Apache-tomcat-6.0.18 \ conf \ server. xml
Add a row to this
- < Connector port="8080" protocol="HTTP/1.1"
-
- connectionTimeout="20000"
-
- redirectPort="8443" URIEncoding="GBK" />
- Example Description: how to print a report using JSP
- Use JSP to print the report Word and Excel)
- Brief Introduction to JSP Technology
- Introduction to JSP Technology
- Introduction to ASP and JSP pages