/*
* Copyright 1999-2001,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.lqk.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.1 $ $Date: 2007/06/21 07:40:28 $
*/
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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SHH2-lib.rar_sh_shh2_shh2 oa_shh2 demo_sshdemo (198个子文件)
example.log.1 100KB
UserDAOImp.class 5KB
TestUserDAO.class 3KB
RegisterAction.class 3KB
LogonAction.class 3KB
ModifyAction.class 3KB
GoEditAction.class 2KB
DelUserAction.class 2KB
Page.class 2KB
SetCharacterEncodingFilter.class 2KB
AbstractUsers.class 2KB
LogonForm.class 2KB
DisplayUsersAction.class 2KB
RegisterForm.class 2KB
PageAction.class 2KB
UserDAO.class 658B
Users.class 504B
.classpath 6KB
Entries 4KB
Entries 605B
Entries 314B
Entries 275B
Entries 268B
Entries 173B
Entries 162B
Entries 143B
Entries 99B
Entries 95B
Entries 66B
Entries 65B
Entries 61B
Entries 50B
Entries 45B
Entries 12B
Entries 11B
Entries 11B
Entries 11B
spring.jar 2.57MB
hibernate3-old.jar 1.6MB
jgroups-2.2.7.jar 1.58MB
itext-1.1.4.jar 1.26MB
xerces-2.6.2.jar 987KB
db-ojb-1.0.3.jar 878KB
jasperreports-1.0.0.jar 795KB
poi-2.5.1.jar 783KB
freemarker.jar 767KB
commons-collections-3.2.jar 558KB
struts.jar 532KB
acegi-security-1.0.4.jar 521KB
mysql-connector-java-5.0.6-bin.jar 515KB
c3p0-0.9.0.jar 476KB
proxool-0.8.3.jar 465KB
c3p0-0.8.5.2.jar 391KB
jmxri.jar 357KB
velocity-1.4.jar 353KB
antlr.jar 350KB
log4j-1.2.9.jar 344KB
cglib-nodep-2.1_2.jar 317KB
quartz.jar 316KB
dom4j-1.6.jar 306KB
ibatis-sqlmap-2.jar 277KB
cglib-2.1.jar 275KB
commons-httpclient.jar 273KB
jaxen-1.1-beta-4.jar 233KB
commons-lang.jar 203KB
jmxremote_optional.jar 202KB
commons-beanutils.jar 184KB
jmxremote.jar 172KB
concurrent-1.3.2.jar 167KB
commons-digester.jar 164KB
cleanimports.jar 139KB
hibernate-annotations.jar 128KB
jotm.jar 121KB
xml-apis.jar 121KB
junit.jar 118KB
ibatis-sqlmap.jar 117KB
oscache-2.1.jar 112KB
commons-dbcp.jar 105KB
jaas.jar 102KB
xapool.jar 90KB
commons-validator.jar 89KB
JAMon.jar 88KB
burlap-2.1.12.jar 83KB
hessian-2.1.12.jar 81KB
ibatis-common-2.jar 76KB
jakarta-oro.jar 64KB
jakarta-oro-2.0.8.jar 64KB
velocity-tools-view-1.1.jar 63KB
commons-pool-1.3.jar 61KB
jdo2.jar 55KB
cos.jar 55KB
toplink-api.jar 49KB
ehcache-1.1.jar 46KB
commons-logging-1.0.4.jar 37KB
commons-logging.jar 37KB
easymock.jar 36KB
commons-attributes-api.jar 35KB
swarmcache-1.0rc2.jar 30KB
commons-attributes-compiler.jar 29KB
asm.jar 26KB
共 198 条
- 1
- 2
资源评论
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功