Java tutorial
/* * Copyright 2012-2014 sammyun.com.cn. All rights reserved. * Support: http://www.sammyun.com.cn * License: http://www.sammyun.com.cn/license */ package com.sammyun.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; import javax.servlet.http.HttpServletResponse; import org.apache.commons.codec.binary.Base64; /** * Filter - ? * * @author Sencloud Team * @version 3.0 */ public class AccessDeniedFilter implements Filter { /** ? */ private static final String ERROR_MESSAGE = "Access denied!"; public void init(FilterConfig filterConfig) throws ServletException { } public void destroy() { } public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"), new String(Base64.decodeBase64("U2hvcHh4Lm5ldA=="), "utf-8")); response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE); } }