One, the development tool can modify the coding place:
1) Window----Preferences---Content Types---Text
Select the file you want to set up, enter "GBK or UTF-8" in the default encoding, and click Update later
2) Window---Preferences---Workspace Text file encoding
Enter "GBK or UTF-8" in the selection box after other, click Applay and OK
3) Right click on Project, file. Select Properties--Text file encoding
Also enter "GBK or UTF-8" in the selection box after other, click Applay and OK
The place where the code can be modified in the document:
Only files that have encoding settings, such as JSP files and HTML files, are limited to
1) <%@ page language= "java" import= "java.util.*" pageencoding= "GBK"%>
2) <meta http-equiv= "Content-type" content= "text/html; charset=gbk " />
Third, using filter to implement the coding filter
1) Filter Processing class
Create a Java class that implements the filter interface
package com.hchx.filter;import java.io.ioexception;import javax.servlet.filter;import javax.servlet.filterchain;import javax.servlet.filterconfig;import javax.servlet.servletexception; import javax.servlet.servletrequest;import javax.servlet.servletresponse;/** * * @ClassName: characterfilter * @Description the implementation class * @author of: |-- coded filters GNODIAD * @date 2014-11-13 Morning 09:27:50 */public class characterfilter implements Filter{// declaration Code processing Parameters private string srccharset;private string Targetcharset;public void destroy () {// TODO pending Method}public void dofilter ( Servletrequest request, servletresponse response,filterchain chain) throws Ioexception, servletexception {system.out.println ("Start encoding Filter ...");// In the console print prompt request.setcharacterencoding (srccharset);// settings pleaseCoding response.setcharacterencoding (Targetcharset);// Set response encoding Chain.dofilter (request, response); // Backward pass}public void init (filterconfig config) throws servletexception { Srccharset = config.getinitparameter ("srcCharSet"); targetcharset = config.getinitparameter ("Targetcharset");}}
2) Configure the filter in Web. xml
<filter><filter-name>charset</filter-name><filter-class> com.hchx.filter.characterfilter</filter-class><init-param><param-name>srccharset</ Param-name><param-value>gbk</param-value></init-param><init-param><param-name >targetcharset</param-name><param-value>gbk</param-value></init-param></filter ><filter-mapping><filter-name>charset</filter-name><url-pattern>/*</url-pattern ></filter-mapping>
Summary: Solve the coding problem, from these three aspects, the specific operation is different from individual development projects.
This article is from the "Gnodiad" blog, make sure to keep this source http://gnodiad.blog.51cto.com/9569162/1575961
MyEclipse Development of Web project coding problem Solving