复习:解决中文乱码问题:

解决中文乱码问题:

 

1:修改JSP页面的编码格式:utf-8;

2: 在传递接收参数中乱码的解决方法:

(1)修改server.xml文件:

maxThreads="150" minSpareThreads="25" maxSpareThreads="75"

     enableLookups="false" redirectPort="8443" acceptCount="100"

     debug="0" connectionTimeout="20000"

 disableUploadTimeout="true" URIEncoding="UTF-8" />

(2)写个过滤器

package com.v512.example;

 

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;

 

public class CharacterEncodingFilter implements Filter {

 

  public void destroy() {

    

  }

 

  public void doFilter(ServletRequest request, ServletResponse response,

         FilterChain chain) throws IOException, ServletException {

         request.setCharacterEncoding("utf-8");

         chain.doFilter(request, response);

         //需要在WEB.XML文件中进行设置

            <filter>

               <filter-name>CharacterEncoding</filter-name>

               <filter-class>com.v512.example.CharacterEncodingFilter</filter-class>

            </filter>

            <filter-mapping>

                 <filter-name>CharacterEncoding</filter-name>

                 <url-pattern>/*</url-pattern>

      </filter-mapping>

  }

 

  public void init(FilterConfig arg0) throws ServletException {

     //

 

  }

 

}

    

3:国际化资源文件出现乱码时:使用eclipce 插件:ResourceBundleEditor_v 0.7.7 .zip

ResourceBundle Editor是一个用于编辑本地化的属性文件(localized properties files)。它让你通一个屏幕就能够同时管理所有相关联属性文件中的key/value信息。它所具有的功能包括:自动为Keys分类,能够提示丢失掉的,重复的,相似的values

你可能感兴趣的:(复习:解决中文乱码问题:)