Solution to java displaying garbled characters:
1. UTF8 solves the problem of JSP Chinese garbled characters
Generally speaking, at the beginning of each page, add :
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% request.setCharacterEncoding("UTF-8"); %>
charset=UTF-8 is used to specify the encoding method output by JSP to the client as "UTF-8";
pageEncoding="UTF-8", in order to allow the JSP engine to It can correctly decode JSP pages containing Chinese characters, which is very effective in LINUX;
request.setCharacterEncoding("UTF-8"); encodes the request in Chinese.
Sometimes, this still cannot solve the problem, and you need to deal with it like this:
String msg = request.getParameter("message"); String str=new String(msg.getBytes("ISO-8859-1"),"UTF-8"); out.println(st);
2. Tomcat 5.5 Chinese garbled code
Just put the %TOMCAT installation directory%/ webapps\servlets -Examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.class file is copied to your webapp directory/filters. If there is no filters directory, create one.
2) Add the following lines to your web.xml:
Set Character Encoding filters.SetCharacterEncodingFilter encoding GBK Set Character Encoding /*
2. Solution to get method
1) Open the server.xml file of tomcat, Find the block and add the following line:
URIEncoding=”GBK”
The complete should be as follows:
2) Restart tomcat, everything is OK.
3. xmlHttpRequest Chinese problem
GBK encoding used for page jsp
Code:
<%@ page contentType="text/html; charset=GBK"%>
For more java knowledge, please pay attention tojava basic tutorialcolumn.
The above is the detailed content of Solution to Chinese garbled characters displayed in Java. For more information, please follow other related articles on the PHP Chinese website!