当前位置: 首页 > news >正文

struts中filter解决中文问题

上一篇: 关于Installshield里一些常见问题的解答(二)--此篇非原创,只是集成了一些网友的解答

ContractedBlock.gif ExpandedBlockStart.gif Code
#filter代码,适用于struts

com.test.filter;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class EncodeFilter
    
extends HttpServlet implements Filter {
  
protected String encoding = null;
  
protected FilterConfig filterConfig = null;
  
protected boolean ignore = true;

//  private FilterConfig filterConfig;
  
//Handle the passed-in FilterConfig
  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;
    }
  }

  
//Process the request/response pair
  public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain chain) 
throws IOException,
      ServletException {
    
if (ignore || (request.getCharacterEncoding() == null)) {
      String encoding 
= selectEncoding(request);
      
if (encoding != null) {
        request.setCharacterEncoding(encoding);
      }
    }
    chain.doFilter(request, response);
  }

  
protected String selectEncoding(ServletRequest request) {
    
return (this.encoding);
  }

  
//Clean up resources
  public void destroy() {
    
this.encoding = null;
    
this.filterConfig = null;
  }
}

 

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
<!--在web.xml中的配置-->
 
<filter>
    
<filter-name>encodefilter</filter-name>
    
<filter-class>com.test.filter.EncodeFilter</filter-class>
    
<init-param>
      
<param-name>encoding</param-name>
      
<param-value>gb2312</param-value>
    
</init-param>
    
<init-param>
      
<param-name>ignore</param-name>
      
<param-value>true</param-value>
    
</init-param>
  
</filter>
  
<filter-mapping>
    
<filter-name>encodefilter</filter-name>
    
<url-pattern>/*</url-pattern>
  
</filter-mapping>


下一篇: sqlserver显示数据库和表及列名

转载于:https://www.cnblogs.com/Cindy_weiwei/archive/2009/05/22/1487269.html

相关文章:

  • ASP.NET内部原理(HttpHandler和HttpModule)
  • SQL Server中临时表与表变量的区别
  • Pro C# 2008 and the .NET 3.5 Platform学习过程
  • 魔兽世界真的还值得你玩下去么?
  • 图解ASP.NET AJAX 1.0 RC开发
  • 动脑筋
  • 在Exchange 2003的03域改名
  • RHEL4- FTP服务(一)vsftpd的安装与启动
  • javascript中获取地址栏参数
  • WCF 4.0中的WS-Discovery
  • 《亮剑.NET:.NET深入体验与实战精要》前言
  • 在 Java 应用程序中定时执行任务
  • 我的座右铭
  • javascript:history.go()和History.back()的区别
  • 如何删除“运行”里面的内容
  • JS 中的深拷贝与浅拷贝
  • 【108天】Java——《Head First Java》笔记(第1-4章)
  • Codepen 每日精选(2018-3-25)
  • CSS实用技巧
  • ES学习笔记(10)--ES6中的函数和数组补漏
  • Fastjson的基本使用方法大全
  • hadoop入门学习教程--DKHadoop完整安装步骤
  • Perseus-BERT——业内性能极致优化的BERT训练方案
  • tweak 支持第三方库
  • 阿里中间件开源组件:Sentinel 0.2.0正式发布
  • 成为一名优秀的Developer的书单
  • 得到一个数组中任意X个元素的所有组合 即C(n,m)
  • 基于 Ueditor 的现代化编辑器 Neditor 1.5.4 发布
  • 检测对象或数组
  • 跨域
  • 入手阿里云新服务器的部署NODE
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • ​如何防止网络攻击?
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • #我与Java虚拟机的故事#连载05:Java虚拟机的修炼之道
  • (12)Hive调优——count distinct去重优化
  • (C语言)共用体union的用法举例
  • (阿里云万网)-域名注册购买实名流程
  • (超简单)构建高可用网络应用:使用Nginx进行负载均衡与健康检查
  • (二)windows配置JDK环境
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (黑马出品_高级篇_01)SpringCloud+RabbitMQ+Docker+Redis+搜索+分布式
  • (五)c52学习之旅-静态数码管
  • (转)Sql Server 保留几位小数的两种做法
  • (转)原始图像数据和PDF中的图像数据
  • .net core 3.0 linux,.NET Core 3.0 的新增功能
  • .net core 6 集成和使用 mongodb
  • .Net core 6.0 升8.0
  • .NET 设计模式初探
  • .NET 中创建支持集合初始化器的类型
  • .net 逐行读取大文本文件_如何使用 Java 灵活读取 Excel 内容 ?
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • [Angular 基础] - 表单:响应式表单
  • [APUE]进程关系(下)
  • [BetterExplained]书写是为了更好的思考(转载)