스타일 파일 필터링, 불법 다운로드 방지

2052 단어 cacheIE

/**
 *        ,       
 * (      ( :HttpWatch)       )
 * @author RuiLin.Xie - xKF24276
 *
 */
public class StyleFilter implements Filter
{

	public void destroy()
	{
		
	}

	/**
	 *        ,       
	 * (      ( :HttpWatch)       )
	 */
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException
	{
		HttpServletRequest request = (HttpServletRequest)arg0;
		
		//         
		String referer = request.getHeader("referer");
		
		/** Cookie   **/
		Cookie[] cookies = request.getCookies();
		String v = null;
		for(int i = 0; cookies != null && i < cookies.length; i++)
		{
			String n = cookies[i].getName();
			if(n.equals("FURL"))
			{
				//  URL   
				v = cookies[i].getValue();
			}
			else
				continue;
		}
		Object oFurl = request.getSession().getAttribute("FURL");
		//      ,    ,     
		if(v == null || oFurl == null || !v.equals(oFurl.toString()))
		{
			System.out.println("    ,    ");
			return;
		}
		/** Cookie     **/
		
		//        ,      ,      
		if(referer != null && referer.startsWith("http://localhost:8080/"))
		{
			//  IE  ,        
			HttpServletResponse response = (HttpServletResponse)arg1;
			response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
			response.setHeader("Pragma","no-cache"); //HTTP 1.0
			response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
			
			arg2.doFilter(arg0, arg1);
		}
		else
		{
			System.out.println("    ,    ");
		}
	}

	public void init(FilterConfig arg0) throws ServletException
	{
		
	}

}

좋은 웹페이지 즐겨찾기