/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.accp.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;
/**
* <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.2 $ $Date: 2004/03/18 16:40:33 $
*/
public class SetCharacterEncodingFilter 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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
WEB开发经典
共79个文件
tld:21个
java:14个
class:14个
需积分: 0 12 下载量 10 浏览量
2008-07-30
14:24:25
上传
评论
收藏 36KB RAR 举报
温馨提示
过程:从最原始的数据库连接方式及对数据库的操作到Spring提供HibernateDaoSupport模板对DAO的支持,从门面工厂到Spring(粘合剂)实现各层之间的交互,采用逐步将现流行框架整合到项目中的方式,让你一目了然,并对各个框架在项目中的运用有一定的认识!总之,绝对是一个不可多得的例子!
资源推荐
资源详情
资源评论
收起资源包目录
email.rar (79个子文件)
email
.mystrutsdata 240B
.springBeans 283B
.myhibernatedata 415B
src
ApplicationResources.properties 592B
service.properties 47B
ApplicationResources_zh_CN.properties 718B
com
accp
dao
DAOFactory.java 896B
UserDAOImpl.java 3KB
IUserDAO.java 343B
exception
UserDefinedException.java 165B
form
UserForm.java 2KB
filter
SetCharacterEncodingFilter.java 6KB
action
BaseAction.java 301B
UserAction.java 2KB
db
DataBase.java 499B
dto
Userinfo.hbm.xml 803B
Userinfo.java 1KB
service
UserServiceImpl.java 2KB
IUserService.java 440B
ServiceFactory.java 958B
util
HibernateSessionFactory.java 2KB
hibernate.cfg.xml 872B
applicationContext.xml 2KB
dao.properties 39B
.project 2KB
WebRoot
META-INF
MANIFEST.MF 39B
WEB-INF
struts-nested.tld 70KB
validator-rules.xml 13KB
scriptfree.tld 2KB
c-1_0.tld 11KB
struts-bean.tld 9KB
fmt-1_0.tld 12KB
struts-html.tld 72KB
struts-logic.tld 14KB
struts-tiles.tld 8KB
fn.tld 7KB
web.xml 1KB
fmt.tld 19KB
x.tld 12KB
x-1_0-rt.tld 7KB
fmt-1_0-rt.tld 11KB
x-1_0.tld 7KB
.struts-config.mex 48B
sql.tld 8KB
classes
ApplicationResources.properties 592B
service.properties 47B
ApplicationResources_zh_CN.properties 718B
com
accp
dao
IUserDAO.class 361B
DAOFactory.class 2KB
UserDAOImpl.class 2KB
exception
UserDefinedException.class 390B
form
UserForm.class 1KB
filter
SetCharacterEncodingFilter.class 2KB
action
UserAction.class 3KB
BaseAction.class 512B
db
DataBase.class 888B
dto
Userinfo.hbm.xml 803B
Userinfo.class 1KB
service
ServiceFactory.class 2KB
IUserService.class 417B
UserServiceImpl.class 2KB
util
HibernateSessionFactory.class 2KB
hibernate.cfg.xml 872B
applicationContext.xml 2KB
dao.properties 39B
struts-config.xml 2KB
sql-1_0.tld 6KB
validation.xml 794B
sql-1_0-rt.tld 5KB
lib
spring.tld 8KB
c-1_0-rt.tld 11KB
permittedTaglibs.tld 1KB
c.tld 16KB
database
email.sql 539B
display.jsp 705B
index.jsp 1KB
show.jsp 508B
.mymetadata 288B
.classpath 7KB
.myeclipse
共 79 条
- 1
资源评论
jianchencool
- 粉丝: 5
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功