MyEclipse Development of Web project coding problem Solving

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.