不知道该过滤器(三个java程序,不大)的具体用途和必要性,谁给我讲讲.
package com.terac.filters;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Referenced classes of package com.terac.filters:
// GZIPResponseWrapper
public class GZIPFilter
implements Filter
{
public GZIPFilter()
{
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException
{
if(req instanceof HttpServletRequest)
{
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
String ae = request.getHeader("accept-encoding");
if(ae != null && ae.indexOf("gzip") != -1)
{
GZIPResponseWrapper gZIPResponseWrapper = new GZIPResponseWrapper(response);
chain.doFilter(req, gZIPResponseWrapper);
gZIPResponseWrapper.finishResponse();
return;
}
chain.doFilter(req, res);
}
}
public void init(FilterConfig filterconfig)
{
}
public void destroy()
{
}
}
////////----------------------
package com.terac.filters;
import java.io.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
// Referenced classes of package com.terac.filters:
// GZIPResponseStream
public class GZIPResponseWrapper extends HttpServletResponseWrapper
{
public GZIPResponseWrapper(HttpServletResponse response)
{
super(response);
origResponse = null;
stream = null;
writer = null;
origResponse = response;
}
public ServletOutputStream createOutputStream()
throws IOException
{
return new GZIPResponseStream(origResponse);
}
public void finishResponse()
{
try
{
if(writer != null)
writer.close();
else
if(stream != null)
stream.close();
}
catch(IOException e) { }
}
public void flushBuffer()
throws IOException
{
stream.flush();
}
public ServletOutputStream getOutputStream()
throws IOException
{
if(writer != null)
throw new IllegalStateException("getWriter() has already been called!");
if(stream == null)
stream = createOutputStream();
return stream;
}
public PrintWriter getWriter()
throws IOException
{
if(writer != null)
return writer;
if(stream != null)
{
throw new IllegalStateException("getOutputStream() has already been called!");
}
else
{
stream = createOutputStream();
writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
return writer;
}
}
public void setContentLength(int i)
{
}
protected HttpServletResponse origResponse;
protected ServletOutputStream stream;
protected PrintWriter writer;
}
//--------------------------
package com.terac.filters;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
public class GZIPResponseStream extends ServletOutputStream
{
protected ByteArrayOutputStream baos;
protected GZIPOutputStream gzipstream;
protected boolean closed;
protected HttpServletResponse response;
protected ServletOutputStream output;
public GZIPResponseStream(HttpServletResponse response)
throws IOException
{
baos = null;
gzipstream = null;
closed = false;
this.response = null;
output = null;
closed = false;
this.response = response;
output = response.getOutputStream();
baos = new ByteArrayOutputStream();
gzipstream = new GZIPOutputStream(baos);
}
public void close()
throws IOException
{
if(closed)
{
throw new IOException("This output stream has already been closed");
} else
{
gzipstream.finish();
byte bytes[] = baos.toByteArray();
response.addHeader("Content-Length", Integer.toString(bytes.length));
response.addHeader("Content-Encoding", "gzip");
output.write(bytes);
output.flush();
output.close();
closed = true;
return;
}
}
public void flush()
throws IOException
{
if(closed)
{
throw new IOException("Cannot flush a closed output stream");
} else
{
gzipstream.flush();
return;
}
}
public void write(int b)
throws IOException
{
if(closed)
{
throw new IOException("Cannot write to a closed output stream");
} else
{
gzipstream.write((byte)b);
return;
}
}
public void write(byte b[])
throws IOException
{
write(b, 0, b.length);
}
public void write(byte b[], int off, int len)
throws IOException
{
if(closed)
{
throw new IOException("Cannot write to a closed output stream");
} else
{
gzipstream.write(b, off, len);
return;
}
}
public boolean closed()
{
return closed;
}
public void reset()
{
}
}
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Referenced classes of package com.terac.filters:
// GZIPResponseWrapper
public class GZIPFilter
implements Filter
{
public GZIPFilter()
{
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException
{
if(req instanceof HttpServletRequest)
{
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
String ae = request.getHeader("accept-encoding");
if(ae != null && ae.indexOf("gzip") != -1)
{
GZIPResponseWrapper gZIPResponseWrapper = new GZIPResponseWrapper(response);
chain.doFilter(req, gZIPResponseWrapper);
gZIPResponseWrapper.finishResponse();
return;
}
chain.doFilter(req, res);
}
}
public void init(FilterConfig filterconfig)
{
}
public void destroy()
{
}
}
////////----------------------
package com.terac.filters;
import java.io.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
// Referenced classes of package com.terac.filters:
// GZIPResponseStream
public class GZIPResponseWrapper extends HttpServletResponseWrapper
{
public GZIPResponseWrapper(HttpServletResponse response)
{
super(response);
origResponse = null;
stream = null;
writer = null;
origResponse = response;
}
public ServletOutputStream createOutputStream()
throws IOException
{
return new GZIPResponseStream(origResponse);
}
public void finishResponse()
{
try
{
if(writer != null)
writer.close();
else
if(stream != null)
stream.close();
}
catch(IOException e) { }
}
public void flushBuffer()
throws IOException
{
stream.flush();
}
public ServletOutputStream getOutputStream()
throws IOException
{
if(writer != null)
throw new IllegalStateException("getWriter() has already been called!");
if(stream == null)
stream = createOutputStream();
return stream;
}
public PrintWriter getWriter()
throws IOException
{
if(writer != null)
return writer;
if(stream != null)
{
throw new IllegalStateException("getOutputStream() has already been called!");
}
else
{
stream = createOutputStream();
writer = new PrintWriter(new OutputStreamWriter(stream, "UTF-8"));
return writer;
}
}
public void setContentLength(int i)
{
}
protected HttpServletResponse origResponse;
protected ServletOutputStream stream;
protected PrintWriter writer;
}
//--------------------------
package com.terac.filters;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPOutputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
public class GZIPResponseStream extends ServletOutputStream
{
protected ByteArrayOutputStream baos;
protected GZIPOutputStream gzipstream;
protected boolean closed;
protected HttpServletResponse response;
protected ServletOutputStream output;
public GZIPResponseStream(HttpServletResponse response)
throws IOException
{
baos = null;
gzipstream = null;
closed = false;
this.response = null;
output = null;
closed = false;
this.response = response;
output = response.getOutputStream();
baos = new ByteArrayOutputStream();
gzipstream = new GZIPOutputStream(baos);
}
public void close()
throws IOException
{
if(closed)
{
throw new IOException("This output stream has already been closed");
} else
{
gzipstream.finish();
byte bytes[] = baos.toByteArray();
response.addHeader("Content-Length", Integer.toString(bytes.length));
response.addHeader("Content-Encoding", "gzip");
output.write(bytes);
output.flush();
output.close();
closed = true;
return;
}
}
public void flush()
throws IOException
{
if(closed)
{
throw new IOException("Cannot flush a closed output stream");
} else
{
gzipstream.flush();
return;
}
}
public void write(int b)
throws IOException
{
if(closed)
{
throw new IOException("Cannot write to a closed output stream");
} else
{
gzipstream.write((byte)b);
return;
}
}
public void write(byte b[])
throws IOException
{
write(b, 0, b.length);
}
public void write(byte b[], int off, int len)
throws IOException
{
if(closed)
{
throw new IOException("Cannot write to a closed output stream");
} else
{
gzipstream.write(b, off, len);
return;
}
}
public boolean closed()
{
return closed;
}
public void reset()
{
}
}
...全文
相关推荐
java中filter的用法(过滤器)
java中filter的用法(过滤器),介绍各种过滤方法
华为MetaERP 账簿、分类账、子分类账的概念分别是什么?
本文介绍了Oracle EBS财务系统中账簿、分类账和子分类账的概念与关系。R11版本中称为"账簿(SOB)",R12后统一改为"分类账(Ledger)",两者都是独立核算主体,包含科目表、本位币等核心要素。分类账分为主分类账、辅助分类账和报表分类账三种类型。子分类账(SLA)是连接业务模块和总账的明细会计层,存储业务单据的明细分录并汇总过账到分类账。数据流向为:业务单据→子分类账→分类账,分类账存储汇总余额并出具报表,而子分类账保留业务明细供追溯。三者构成完整的财务
Oracle EBS GL总帐模块操作手册:帐套配置、日记帐过帐与余额查询SQL实战
总帐模块是ERP财务体系的核心,负责凭证处理、余额计算和报表输出。其原理基于帐套与会计期间配置,通过日记帐录入、过帐和冲销实现数据流转,最终在余额表中按多维存储。技术价值在于确保财务数据准确性和合规性,应用场景包括月结、审计和内部管理报表。本文以Oracle EBS GL模块为例,结合操作手册和SQL代码,详解帐套配置、日记帐过帐、余额查询及FSG报表等关键操作,帮助IT支持和顾问快速排错。
cookie、session和java过滤器结合实现登陆程序
主要为大家详细介绍了cookie、session和java过滤器结合实现登陆程序的具体代码,感兴趣的朋友可以参考一下
管道过滤器程序,主要用java实现
管道过滤器程序,主要用java实现 管道过滤器程序,主要用java实现


