ServletResponsefilter is encrypted by HTML to protect artist labor.

xiaoxiao2021-03-06  85

The Filter class code is as follows:

Package com.youk.wf.filter;

Import javax.servlet. *; import javax.servlet.http. *; import java.io. *; import java.util. *; import com.youk.util.htmlencode; / **

Title: btoall

description:

Copyright: Copyright (c) 2004

Company: youkone incningbo. @Author Victor Wu (WooWind@sina.com) @ Version 1.0 * /

public class HtmlProtectFilter extends HttpServlet implements Filter {private FilterConfig filterConfig; HtmlEncode encode = new HtmlEncode (); // Handle the passed-in FilterConfig public void init (FilterConfig filterConfig) throws ServletException {this.filterConfig = filterConfig;}

// Process the request / response pair public void doFilter (ServletRequest request, ServletResponse response, FilterChain filterChain) {try {HttpServletResponse httpResponse = (HttpServletResponse) response; HttpServletRequest httpRequest = (HttpServletRequest) request; String path = httpRequest.getRequestURI (); / / String mimitype = filterconfig.getServletContext (). GetMimetype (path); httprequest.setcharacterencoding ("gbk"); string ext = ".ww"; if (path.length ()> 2) {path = path.substring (path] .length () - 3, Path.Length ()). toLowercase ();} // Need a resource of the order; after 2 digits; if (! path.equals (ext)) {filterchain.dofilter (httpRequest, response) } Else {system.out.println ("ext =" path); httpresponse.setContentType ("text / html; charSet = GBK"); ResponseWrapper W Rapper = new responseWrapper (httpresponse); filterchain.dofilter (httpRequest, wrapper);}} catch (exception ex) {ex.printstacktrace ();}}

/ ** * * / public void destroy () {}

/ ** * *

Title: SMS *

Description: SMS *

Copyright: Copyright (c) 2003 *

Company: Youk Inc. * @author Feng Wu Bin (woowind@sina.com) * @version 1.0 * / public class ResponseWrapper extends HttpServletResponseWrapper {private PrintWriter printWriter; private ResponseOutputStream outputStream; public ResponseWrapper (ServletResponse response) throws java.io.IOException {super ( (HttpServletResponse) response); outputStream = new ResponseOutputStream (response.getOutputStream ()); printWriter = new PrintWriter (outputStream);} public ServletOutputStream getOutputStream () throws java.io.IOException {return outputStream;} public PrintWriter getWriter () throws java .io ioException {return printwriter;} } / ** * * @Param args string [] * / public static void main (String [] args) {Try {string cn = "Hello"; int h = cn.charat (0); string s = new integer (h) .tohexString (h); // string result = java.net.urlencoder.Encode (, "gbk"); system.out.println (s);} catch (exception ex) {ex.printstacktrace (); }} Public class responseoutputstream Extends servletoutputstream {Private OutputStream OutputStream; Private ByteArrayoutputStream ArrayStream; private bolean closed = false;

public ResponseOutputStream (OutputStream stream) {outputStream = stream; arrayStream = new ByteArrayOutputStream ();} public void write (int i) throws java.io.IOException {arrayStream.write (i);}

Public void write (byte [] b) throws java.io ioException {ArrayStream.write (b);}

Public void write (byte [] b, int a, int bb) throws java.io.ioException {ArrayStream.write (b, a, bb);}

Public void close () throws java.io.ioException {if (! closed) {OutputStream.close (); closed = true;}}

Public void flush () throws java.io.ioException {if (arraystream.size ()! = 0) {if (! closed) {processstream (); arraystream = new byteArrayoutputStream ();}}}

private void processStream () throws java.io.IOException {System.out.println ( "replace."); outputStream.write (replaceContent (arrayStream.toByteArray ())); outputStream.flush ();} byte [] replaceContent ( Byte [] Bytescontent) {Try {string s = new string (bytescontent, "gbk"); if (S.TolowerCase (). Indexof ("")! = -1) {string encodehtml = Encode.Encode s); string adds = "