本文整理了Java中javax.servlet.Filter
类的一些代码示例,展示了Filter
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Filter
类的具体详情如下:
包路径:javax.servlet.Filter
类名称:Filter
[英]A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.
Filters perform filtering in the doFilter
method. Every Filter has access to a FilterConfig object from which it can obtain its initialization parameters, and a reference to the ServletContext which it can use, for example, to load resources needed for filtering tasks.
Filters are configured in the deployment descriptor of a web application.
Examples that have been identified for this design are:
doFilter
方法中执行过滤。每个筛选器都可以访问一个FilterConfig对象,从中可以获取其初始化参数,还可以访问对ServletContext的引用,例如,它可以使用该引用加载筛选任务所需的资源。代码示例来源:origin: jenkinsci/jenkins
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
if(position==filters.length) {
// reached to the end
chain.doFilter(request,response);
} else {
// call next
filters[position++].doFilter(request,response,this);
}
}
}.doFilter(request,response);
代码示例来源:origin: spring-projects/spring-framework
/**
* Initialize all the filters, calling each one's init method in turn in the order supplied.
* @see Filter#init(FilterConfig)
*/
@Override
public void init(FilterConfig config) throws ServletException {
for (Filter filter : this.filters) {
filter.init(config);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void destroy() {
this.delegate.destroy();
}
代码示例来源:origin: org.jasig.portal/uPortal-spring
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (wrappedFilter == null) {
throw new ServletException("No wrappedFilter configured");
}
if (this.enable) {
this.wrappedFilter.doFilter(request, response, chain);
} else {
chain.doFilter(request, response);
}
}
代码示例来源:origin: com.google.inject.extensions/guice-servlet
throw new ServletException(
"Filters must be bound as singletons. "
+ filterKey
filter.init(
new FilterConfig() {
@Override
代码示例来源:origin: sitemesh/sitemesh3
protected void deployNewFilter(Filter newFilter) throws ServletException {
Filter oldFilter = filter;
if (newFilter == null) {
throw new ServletException("Cannot deploy null filter");
}
newFilter.init(filterConfig);
filter = newFilter;
if (oldFilter != null) {
oldFilter.destroy();
}
}
代码示例来源:origin: Atmosphere/atmosphere
try {
filter = filterConfig.getFilter();
filter.doFilter(request, response, this);
} catch (IOException e) {
throw e;
throw e;
} catch (Throwable e) {
throw new ServletException("Throwable", e);
servlet.service(request, response);
} else {
RequestDispatcher rd = configImpl.getServletContext().getNamedDispatcher("default");
if (rd == null) {
throw new ServletException("No Servlet Found");
throw e;
} catch (Throwable e) {
throw new ServletException("Throwable", e);
代码示例来源:origin: sitemesh/sitemesh3
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
if (!initialized) {
throw new ServletException(getClass().getName() + ".init(FilterConfig) was not called");
}
reloadIfNecessary();
filter.doFilter(servletRequest, servletResponse, filterChain);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Pass the call on to the Filter/Servlet.
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws ServletException, IOException {
if (this.filter != null) {
this.filter.doFilter(request, response, this.nextFilterChain);
}
else {
Assert.state(this.servlet != null, "Neither a Filter not a Servlet set");
this.servlet.service(request, response);
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Actually invoke the delegate Filter with the given request and response.
* @param delegate the delegate Filter
* @param request the current HTTP request
* @param response the current HTTP response
* @param filterChain the current FilterChain
* @throws ServletException if thrown by the Filter
* @throws IOException if thrown by the Filter
*/
protected void invokeDelegate(
Filter delegate, ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
delegate.doFilter(request, response, filterChain);
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testFilterBasic() throws ServletException, IOException {
Filter filter = makeFilter();
try {
filter.init(makeFilterConfig());
filter.doFilter(makeRequest(), makeResponse(), makeFilterChain());
}
finally {
filter.destroy();
}
}
代码示例来源:origin: nutzam/nutz
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (proxy == null) {
synchronized (lock) {
if (proxy == null) {
Ioc ioc = Mvcs.ctx().getDefaultIoc();
Filter proxy = ioc.get(null, beanName);
proxy.init(filterConfig);
this.proxy = proxy;
}
}
}
proxy.doFilter(request, response, chain);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Reset the proxies and filter for a change in {@link SecurityRealm}.
*/
public void reset(SecurityRealm securityRealm) throws ServletException {
if (securityRealm != null) {
SecurityRealm.SecurityComponents sc = securityRealm.getSecurityComponents();
AUTHENTICATION_MANAGER.setDelegate(sc.manager);
USER_DETAILS_SERVICE_PROXY.setDelegate(sc.userDetails);
REMEMBER_ME_SERVICES_PROXY.setDelegate(sc.rememberMe);
// make sure this.filter is always a valid filter.
Filter oldf = this.filter;
Filter newf = securityRealm.createFilter(this.filterConfig);
newf.init(this.filterConfig);
this.filter = newf;
if(oldf!=null)
oldf.destroy();
} else {
// no security related filter needed.
AUTHENTICATION_MANAGER.setDelegate(null);
USER_DETAILS_SERVICE_PROXY.setDelegate(null);
REMEMBER_ME_SERVICES_PROXY.setDelegate(null);
filter = null;
}
}
代码示例来源:origin: Atmosphere/atmosphere
/**
* Initialize the {@link Filter}
*
* @throws javax.servlet.ServletException
*/
public void init() throws ServletException {
for (FilterConfigImpl f : filters) {
if (f != null) {
f.getFilter().init(f);
}
}
if (servlet != null) {
servlet.init(configImpl);
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testInit() {
Filter filter = makeFilter();
try {
filter.init(makeFilterConfig());
}
catch (ServletException e) {
assertNotNull(e.getMessage());
}
finally {
filter.destroy();
}
}
代码示例来源:origin: igniterealtime/Openfire
servlet.destroy();
filter.destroy();
代码示例来源:origin: org.jasig.portal/uPortal-spring
@Override
public void init(FilterConfig filterConfig) throws ServletException {
if (wrappedFilter == null) {
throw new ServletException("No wrappedFilter configured");
}
if (this.enable) {
this.wrappedFilter.init(filterConfig);
}
}
代码示例来源:origin: org.sitemesh/sitemesh
protected void deployNewFilter(Filter newFilter) throws ServletException {
Filter oldFilter = filter;
if (newFilter == null) {
throw new ServletException("Cannot deploy null filter");
}
newFilter.init(filterConfig);
filter = newFilter;
if (oldFilter != null) {
oldFilter.destroy();
}
}
代码示例来源:origin: org.sitemesh/sitemesh
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
if (!initialized) {
throw new ServletException(getClass().getName() + ".init(FilterConfig) was not called");
}
reloadIfNecessary();
filter.doFilter(servletRequest, servletResponse, filterChain);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Pass the call on to the Filter/Servlet.
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response) throws ServletException, IOException {
if (this.filter != null) {
this.filter.doFilter(request, response, this.nextFilterChain);
}
else {
Assert.state(this.servlet != null, "Neither a Filter not a Servlet set");
this.servlet.service(request, response);
}
}
内容来源于网络,如有侵权,请联系作者删除!