Home >Java >JavaBase >Solution to Chinese garbled code in Java page

Solution to Chinese garbled code in Java page

尚
Original
2019-12-10 10:58:393180browse

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"%>

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");

                 ........

     }

}

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

Tomcat server. The 6be2fa4ba28b9cec816fadb9d4df83db configuration in the xml document is added

useBodyEncodingForURI="true" IEncoding="utf-8" URIEncoding="utf-8"

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!

Statement:
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
Previous article:Java web garbled solutionNext article:Java web garbled solution