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
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!