/*
* 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);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
时尚网上购物商城(基于java语言实现) (274个子文件)
RequestDumperFilter.class 6KB
UserBean.class 4KB
ShoppingCartAction.class 4KB
productBean.class 4KB
AddShopAndSubAction.class 3KB
SubBean.class 3KB
AddProductAction.class 3KB
ShopBean.class 3KB
UserLoginAction.class 3KB
LeaBean.class 2KB
AddLinkAction.class 2KB
AddNoticeBean.class 2KB
GetPassAction.class 2KB
AddLinkBean.class 2KB
ExampleFilter.class 2KB
updateWareAction.class 2KB
UserRegAction.class 2KB
DelMessageAction.class 2KB
ObjectShopBean.class 2KB
DelSubAction.class 2KB
loginAction.class 2KB
SetCharacterEncodingFilter.class 2KB
SetCharacterEncodingFilter.class 2KB
TextBean.class 2KB
DeleProAction.class 2KB
AddNoticeAction.class 2KB
UserUpdateAction.class 2KB
DeleUserAction.class 2KB
ClearCartAction.class 2KB
DelMessAction.class 2KB
DelNoticeAction.class 1KB
QueryBean.class 1KB
ShoppBean.class 1KB
loginbean.class 1KB
DelLinkAction.class 1KB
leakAction.class 1KB
ShoppingCart.class 1KB
DBConnection.class 1KB
MyRequestProcesser.class 1KB
SubOrderBean.class 1021B
LinkBean.class 1012B
.classpath 568B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 1KB
Thumbs.db 140KB
Thumbs.db 41KB
003.gif 1.92MB
adminmanager_3.gif 108KB
top_1.gif 49KB
bag_1.gif 49KB
adminmanager_1.gif 49KB
adminmanager_2.gif 28KB
looksub_4.gif 23KB
006.gif 16KB
009.gif 15KB
looksub_1.gif 15KB
asub_1.gif 15KB
015.gif 15KB
007.gif 15KB
008.gif 15KB
alookuser_1.gif 15KB
lookware_3.gif 14KB
010.gif 14KB
005.gif 14KB
002.gif 13KB
usereg_5.gif 12KB
lookpassword_5.gif 12KB
edituser_1.gif 11KB
lookware_5.gif 11KB
usereg_2.gif 11KB
leavword_1.gif 11KB
lookware_1.gif 11KB
addware_5.gif 11KB
usereg_1.gif 11KB
leave_3.gif 11KB
bag_3.gif 11KB
leave_5.gif 11KB
lookpassword_1.gif 11KB
001.gif 11KB
alogin_5.gif 10KB
bag_6.gif 10KB
alogin_1.gif 10KB
affiche_1.gif 10KB
alink_1.gif 9KB
looksub_2.gif 9KB
leave_21.gif 9KB
top_3.gif 9KB
top_14.gif 8KB
top_16.gif 8KB
addware_1.gif 8KB
inputsub_1.gif 8KB
011.gif 7KB
leave_2.gif 7KB
lookpassword_3.gif 7KB
bag_5.gif 6KB
leave_4.gif 6KB
012.gif 5KB
016.gif 5KB
alogin_2.gif 5KB
usereg_3.gif 5KB
共 274 条
- 1
- 2
- 3
资源评论
- xingzhe0092012-04-27调试过程中出来点小错误
- 老族2017-12-05登录页面一直报500.
- 梦未央2012-03-15就是一个培训学校的项目,不太好
- red81772013-04-11对于初学者还是有帮助的
mingyunduoshou
- 粉丝: 34
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- python tkinter-08-盒子模型.ev4.rar
- Doozy UI Manager 2023
- 基于matlab实现夜间车牌识别程序(1).rar
- 基于matlab实现无线传感器网络无需测距定位算法matlab源代码 包括apit,dv-hop,amorphous在内的共7个
- 基于python的yolov5实现的旋转目标检测
- 基于matlab实现无线传感器网络 CAB定位仿真程序 这是无线传感器节点定位CAB算法的仿真程序,由matlab完成.rar
- 基于matlab实现图像处理,本程序使用背景差分法对来往车辆进行检测和跟踪.rar
- 基于matlab实现视频监控中车型识别代码,自己写的,希望和大家多多交流.rar
- springcodespringcodespringcodespringcode
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功