jsp路径参数: encodeURI(encodeURI(中文,"utf-8"),"utf-8")
action: URLDecoder.decode(URLDecoder.decode(request.getParameter("中文"), "utf-8"), "utf-8")
=======================================================================================
在国内项目中,经常会遇到页面传值为中文的情况,经常会遇到乱码。
现将我之前的一个过滤器放上来,供大家参考。(注:版权声明中的CottSoft.com为本人的项目,所以大家放心用。)
定义过滤器:
CharacterEncodingFilter.java
/*
**************************************************************************
* Confidentiality Information:
*
* This module is the confidential and proprietary information of
* CottSoft.com; it is not to be copied, reproduced, or
* transmitted in any form, by any means, in whole or in part,
* nor is it to be used for any purpose other than that for which
* it is expressly provided without the written permission of
* CottSoft.com.
*
**************************************************************************
*
* PROGRAM DESCRIPTION:
*
* This filter is processing Chinese code.
*
*
*
**************************************************************************
* CHANGE HISTORY:
*
* Date: by: Reason:
* YYYY-MM-DD IN Reason text.
*
* 2010-11-28 Simon Hoo Initial Version.
*************************************************************************
*/
package com.cottsoft.common.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;
public class CharacterEncodingFilter implements Filter {
private String encoding = null;
public void init(FilterConfig filterConfig) throws ServletException {
this.encoding = filterConfig.getInitParameter("encoding");
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
response.setContentType("text/html;charset=" + encoding);
filterChain.doFilter(request, response);
}
public void destroy() {
// destroy code.
}
}
配制web.xml