Home >Java >javaTutorial >How to solve the garbled jsp source file
This article will introduce several ways to solve the problem of garbled JSP files. The details are as follows. I hope it will be a reference for everyone.
Check whether the encoding format is set in the jsp file header:
By the way, set it:
<meta>
View the encoding format of the project: set to UTF-8
project–》properties:
If the jsp file is copied directly, you should also check it, right-click the jsp File, select properties, and set the encoding format:
The above generally solves the problem of garbled Chinese characters on the page itself. If there are still problems, such as garbled characters in the submitted form, etc., you need to respond in the request header. Header setting encoding:
//设置编码格式 req.setCharacterEncoding("UTF-8"); resp.setCharacterEncoding("UTF-8");
4. If the garbled code has not been solved in the end, set the tomcat server encoding format. By default, the encoding method used by tomcat: iso8859-1, open the setting.xml file ( (In the tomcat folder conf) Find the following code:
<connector></connector>
This code specifies the port number and other information for Tomcat to listen to HTTP requests.
You can add an attribute here: URIEncoding. Set the attribute value to UTF-8 to allow Tomcat (default ISO-8859-1 encoding) to process get requests in UTF-8 encoding.
<connector></connector>
Related learning recommendations: java basics
The above is the detailed content of How to solve the garbled jsp source file. For more information, please follow other related articles on the PHP Chinese website!