Home > Java > JavaBase > body text

Solution to Chinese garbled code in Java page

Release: 2019-12-10 10:58:39
Original
3127 people have browsed it

Solution to Chinese garbled code in Java page

1. Set the Encoding option in eclips, window->Preferences->web->JSP Files to UTF-8

2. Modify the jsp file The header is UTF-8

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Copy after login

3. Set the request object encoding in the servlet

public class RegisterServlet extends HttpServlet{
     public void doGet(HttpServletRequest request,HttpServletResponse response)
                 throws ServletException,IOException{

                 request.setCharacterEncoding("UTF-8");

                 ........

     }

}
Copy after login

4. If it is still garbled, set the configuration file in tomat

Tomcat server. The configuration in the xml document is added

useBodyEncodingForURI="true" IEncoding="utf-8" URIEncoding="utf-8"
Copy after login

For more java knowledge, please pay attention to the java Basic Tutorial column.

The above is the detailed content of Solution to Chinese garbled code in Java page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template