/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 filters;
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: 500674 $ $Date: 2007-01-28 00:15:00 +0100 (dim., 28 janv. 2007) $
*/
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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
struts+spring+hibernate开发的+开发环境_eclipse3.1+MyEclipse4.1+tomcat5
共205个文件
jpg:52个
class:29个
java:29个
需积分: 3 9 下载量 91 浏览量
2008-11-06
00:22:09
上传
评论
收藏 3.22MB RAR 举报
温馨提示
struts+spring+hibernate开发的+开发环境_eclipse3.1+MyEclipse4.1+tomcat5新闻发布(用于学习)
资源推荐
资源详情
资源评论
收起资源包目录
struts+spring+hibernate开发的+开发环境_eclipse3.1+MyEclipse4.1+tomcat5 (205个子文件)
UserDAO.class 5KB
ReplayDAO.class 5KB
NewsDAO.class 5KB
NewstypeDAO.class 5KB
UserPl.class 4KB
managerAddNews.class 4KB
ExecuteModifyNews.class 3KB
UserMethod.class 3KB
ReplayAction.class 3KB
UserAction.class 3KB
HibernateSessionFactory.class 2KB
RegisterForm.class 2KB
LoginAction.class 2KB
newsTypeMethod.class 2KB
replayMethod.class 2KB
newsMethod.class 2KB
RegisterAction.class 2KB
NewsTypeManagermentServlet.class 2KB
News.class 2KB
LoginForm.class 2KB
SetCharacterEncodingFilter.class 2KB
User.class 2KB
Replay.class 2KB
managerAddType.class 2KB
cancelservlet.class 1KB
Page.class 1KB
Newstype.class 1KB
BaseHibernateDAO.class 538B
IBaseHibernateDAO.class 188B
.classpath 1KB
style.css 4KB
css.css 4KB
css.css 4KB
denglu_01.gif 17KB
denglu_04.gif 12KB
denglu_06.gif 9KB
071028100116722.gif 4KB
071028100332784.gif 4KB
denglu_10.gif 3KB
071028095648878.gif 2KB
he8he8.gif 1KB
denglu_02.gif 1KB
0010.gif 1KB
blank.gif 893B
denglu_03.gif 573B
club-50.gif 487B
denglu_05.gif 423B
denglu_07.gif 236B
071028100554019.gif 185B
denglu_09.gif 171B
top_bg.gif 157B
071028100432644.gif 117B
b.gif 111B
071028095959706.gif 106B
051211135335546.gif 76B
071028100227753.gif 64B
denglu_12.gif 50B
051211135342000.gif 48B
分隔符.gif 43B
index(1).htm 3KB
opr_insertflow.htm 28B
opr_insertflow.htm 28B
msbase.jar 280KB
commons-beanutils.jar 184KB
commons-beanutils-core.jar 165KB
mssqlserver.jar 66KB
msutil.jar 58KB
commons-beanutils-bean-collections.jar 25KB
SetCharacterEncodingFilter.java 6KB
UserDAO.java 4KB
NewsDAO.java 4KB
ReplayDAO.java 4KB
NewstypeDAO.java 4KB
managerAddNews.java 4KB
UserPl.java 3KB
HibernateSessionFactory.java 3KB
ReplayAction.java 2KB
newsMethod.java 2KB
ExecuteModifyNews.java 2KB
newsTypeMethod.java 2KB
managerAddType.java 2KB
replayMethod.java 2KB
UserMethod.java 2KB
cancelservlet.java 2KB
RegisterForm.java 2KB
News.java 2KB
UserAction.java 2KB
User.java 2KB
LoginAction.java 2KB
LoginForm.java 1KB
RegisterAction.java 1KB
NewsTypeManagermentServlet.java 1KB
Replay.java 1KB
Page.java 1KB
Newstype.java 1KB
BaseHibernateDAO.java 381B
IBaseHibernateDAO.java 234B
411.JPG 680KB
311.JPG 586KB
211.JPG 382KB
共 205 条
- 1
- 2
- 3
资源评论
yywork
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功