`
yuhujiaolong
  • 浏览: 5599 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
社区版块
存档分类
最新评论

encoding

阅读更多
/**
*
*/
package com.huawei.cloud.util.encondFilter;

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;

/**
* <p>
* Example filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding. Configuration of this filter is based on
* the following initialization parameters:
* </p>
* <ul>
* <li><strong>encoding</strong> - The character encoding to be configured
* for this request, either conditionally or unconditionally based on the
* <code>ignore</code> initialization parameter. This parameter is
* required, so there is no default.</li>
* <li><strong>ignore</strong> - If set to "true", any character encoding
* specified by the client is ignored, and the value returned by the
* <code>selectEncoding()</code> method is set. If set to "false,
* <code>selectEncoding()</code> is called <strong>only</strong> if the
* client has not already specified an encoding. By default, this parameter
* is set to "true".</li>
* </ul>
*
* <p>
* Although this filter can be used unchanged, it is also easy to subclass
* it and make the <code>selectEncoding()</code> method more intelligent
* about what encoding to choose, based on characteristics of the incoming
* request (such as the values of the <code>Accept-Language</code> and
* <code>User-Agent</code> headers, or a value stashed in the current
* user's session.
* </p>
*
* @author Craig McClanahan
* @version $Revision: 1.1 $ $Date: 2008/04/23 14:24:22 $
*/

public class EncondFilter implements Filter {

// ----------------------------------------------------- Instance
// Variables

/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;

/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;

/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;

// --------------------------------------------------------- Public
// Methods

/**
* Take this filter out of service.
*/
public void destroy() {

this.encoding = null;

this.filterConfig = null;

}

/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request
*            The servlet request we are processing
* @param result
*            The servlet response we are creating
* @param chain
*            The filter chain we are processing
*
* @exception IOException
*                if an input/output error occurs
* @exception ServletException
*                if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

// Conditionally select and set the character encoding to be used

if (ignore || (request.getCharacterEncoding() == null)) {

String encoding = selectEncoding(request);

if (encoding != null)

request.setCharacterEncoding(encoding);

}

// Pass control on to the next filter

chain.doFilter(request, response);

}

/**
* Place this filter into service.
*
* @param filterConfig
*            The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {

this.filterConfig = filterConfig;

this.encoding = filterConfig.getInitParameter("encoding");

String value = filterConfig.getInitParameter("ignore");

if (value == null)

this.ignore = true;

else if (value.equalsIgnoreCase("true"))

this.ignore = true;

else if (value.equalsIgnoreCase("yes"))

this.ignore = true;

else

this.ignore = false;

}

// ------------------------------------------------------ Protected
// Methods

/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* <p>
* The default implementation unconditionally returns the value
* configured by the <strong>encoding</strong> initialization parameter
* for this filter.
*
* @param request
*            The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request) {

return (this.encoding);

}

}
分享到:
评论

相关推荐

    vs FileEncoding插件 2019

    《Visual Studio FileEncoding插件:提升代码编辑体验的利器》 在软件开发过程中,文件编码格式的选择和管理是不可忽视的重要环节。尤其是在处理跨平台或多语言项目时,正确的编码格式能确保代码的可读性和兼容性。...

    谷歌设置编码插件SetCharacterEncoding

    **谷歌设置编码插件SetCharacterEncoding详解** 在日常的网页浏览和开发过程中,我们经常会遇到网页内容编码不正确的问题,导致乱码现象。为了解决这个问题,开发者们创建了一款名为"SetCharacterEncoding"的谷歌...

    Gma.QrCodeNet.Encoding.Net35.dll、Gma.QrCodeNet.Encoding.Net45.dll二维码工具类库

    《Gma.QrCodeNet.Encoding.Net35.dll与Gma.QrCodeNet.Encoding.Net45.dll:二维码编码库解析》 在信息化飞速发展的今天,二维码作为一种高效的信息载体,已经广泛应用在我们的生活中。无论是产品包装、广告宣传还是...

    mod_encoding-2.2.0-1.i386.tar.gz

    LoadModule encoding_module modules/mod_encoding.so Header add MS-Author-Via "DAV" &lt;IfModule mod_encoding.c&gt; EncodingEngine on NormalizeUsername on SetServerEncoding GBK ...

    com.lifesting.tool.encoding_1.0.0.jar

    《Eclipse文件转码插件:com.lifesting.tool.encoding_1.0.0.jar解析》 在IT行业中,开发工具的效率与便利性对于程序员来说至关重要。Eclipse作为一款广泛应用的Java集成开发环境(IDE),其丰富的插件库使得开发者...

    Gma.QrCodeNet.Encoding(2.0-4.5)版本合集下载

    《Gma.QrCodeNet.Encoding库的全面解析与应用指南》 Gma.QrCodeNet.Encoding是一个用于生成和解码二维码的.NET库,它支持多种.NET框架版本,包括从2.0到4.5,以及.NET Core 4.5。这个库以其高效、灵活和易于使用的...

    Set Character Encoding_0.51.zip

    标题中的“Set Character Encoding_0.51.zip”指的是一个版本为0.51的名为“Set Character Encoding”的软件插件的压缩包文件。这个插件是专为谷歌浏览器(Google Chrome)设计的,其主要功能是允许用户手动调整...

    mod_encoding-

    4. 配置Apache服务器,将 `mod_encoding` 加入到加载模块的配置中,如在 `httpd.conf` 文件中添加 `LoadModule encoding_module modules/mod_encoding.so`。 5. 重启Apache服务器使更改生效,可以使用 `sudo service...

    parquet-encoding-1.8.2-API文档-中文版.zip

    赠送jar包:parquet-encoding-1.8.2.jar; 赠送原API文档:parquet-encoding-1.8.2-javadoc.jar; 赠送源代码:parquet-encoding-1.8.2-sources.jar; 赠送Maven依赖信息文件:parquet-encoding-1.8.2.pom; 包含...

    mod_encoding_2010.zip

    "mod_encoding_2010.zip"这个压缩包文件,显然与Apache服务器的一个特定模块——mod_encoding有关,该模块主要解决的是Apache在处理包含非ASCII字符(如中文)的URL路径时的问题。 Apache默认情况下,可能会对包含...

    ImportError:无法从“django.utils.encoding”导入名称“force text”Python 错误

    在Python和Django框架的开发过程中,可能会遇到各种错误,其中"ImportError:无法从'django.utils.encoding'导入名称'force text'"是一个常见的问题。这个错误意味着你的代码尝试从'django.utils.encoding'模块导入...

    Encoding

    修改输出编码方式 boolean SetToEncoding(string $ToEncoding) 函数参数只能使用上述5种编码方式,区分大小写,如GBK不能写成gbk 如果设置成功,返回true,如果使用了错误的编码名,返回false,并现实错误信息 ...

    Encoding内码查看工具

    在IT领域,编码(Encoding)是数据转换成可读格式的过程,特别是在文本处理中,它涉及到将字符转换为数字表示,以便计算机可以处理和存储。本文将深入探讨C#编程语言中的编码概念以及如何使用“Encoding内码查看工具...

    字符编码转换器(Encoding Tool)EncodingTool

    《字符编码转换器(Encoding Tool)——深入理解与应用》 字符编码是计算机处理文本的基础,不同的编码方式决定了如何存储和显示各种语言的字符。在信息化社会中,由于全球化的需求,我们常常需要面对不同编码格式...

    64位环境的mod_encoding模块

    针对中文网址(中文URL)的支持问题,"64位环境的mod_encoding模块"提供了一个解决方案。这个模块是专门为了解决在64位操作系统,如64位CentOS 5.5上,Apache2.2.15版本对中文URL处理不兼容的问题而设计的。 Apache...

    Encoding类使用说明

    ### Encoding类使用说明 #### 一、概述 在.NET Framework中,`System.Text.Encoding`类提供了处理字符编码的强大工具。编码是指将Unicode字符转换为字节序列的过程;而解码则是相反的操作,即将字节序列转换回...

    WEBLOGIC8+AJAX setCharacterEncoding报错

    描述中提到的"NoSuchMethodError setCharacterEncoding(Ljava/lang/String;)V"是一个Java运行时异常,意味着在类装载时尝试调用的方法在该类的Class文件中存在,但在链接阶段找不到。这通常发生在试图执行的方法在...

    mod_encoding(apache支持中文路径工具)

    `mod_encoding`模块是Apache的一个扩展,专门设计来解决这个问题,使得Apache能够正确地识别和处理包含多语言字符的URL和文件路径。 ### 1. `mod_encoding`模块介绍 `mod_encoding`是Apache HTTP服务器的一个模块...

    TextEncoding 文件编码批量转换工具

    《TextEncoding:高效便捷的文件编码批量转换工具》 在信息技术领域,文件编码是一个至关重要的概念,它决定了数据如何在不同系统间正确地传递和显示。TextEncoding是一款专为处理文件编码问题而设计的实用工具,它...

    Specification of Packed Encoding Rules (PER).pdf

    ### Packed Encoding Rules (PER) 规范解析 #### 引言 《Packed Encoding Rules (PER)》规范文档详细介绍了ITU-T所推荐的Packed Encoding Rules(PER)编码技术,这是一种高效的编码方法,用于将Abstract Syntax ...

Global site tag (gtag.js) - Google Analytics